Fix “No function matches the given name and argument types ‘list_concat…” When Using array_push_front() or array_push_back() in DuckDB

If you’re getting a binder error that reads something like “No function matches the given name and argument types ‘list_concat(STRING_LITERAL, VARCHAR[][])’. You might need to add explicit type casts.” in DuckDB when using either the array_push_front() or array_push_back() functions, it could be due to a slight syntax error.

This error can occur if you have the two arguments around the wrong way. This can be easy to do, as the DuckDB documentation states that these functions are aliases for other functions, but it doesn’t mention that the argument order needs to be switched.

To fix this error, try switching the order of your arguments. Specifically, make sure the list comes first and the element to prepend/append comes second.

Example of Error

Here’s an example of code that produces the error:

SELECT array_push_back('apple', ['banana', 'cherry']);

Output:

Binder Error: No function matches the given name and argument types 'list_concat(STRING_LITERAL, VARCHAR[][])'. You might need to add explicit type casts.
Candidate functions:
list_concat(ANY[], ANY[]) -> ANY[]

LINE 1: SELECT array_push_back('apple', ['banana', 'ch...
^

We get the same error with array_push_front():

SELECT array_push_front('apple', ['banana', 'cherry']);

Output:

Binder Error: No function matches the given name and argument types 'list_concat(VARCHAR[][], STRING_LITERAL)'. You might need to add explicit type casts.
Candidate functions:
list_concat(ANY[], ANY[]) -> ANY[]

LINE 1: SELECT array_push_front('apple', ['banana', 'c...
^

If you’re familiar with list_prepend() and/or list_append() this error may seem strange, as passing the same arguments in the same order produce the desired result. Given the DuckDB documentation states that array_push_back() is an alias for list_append() and array_push_front() is an alias for list_prepend(), this issue could be a bit unexpected.

Solution

Fortunately, the solution is easy; switch the argument order:

SELECT 
    array_push_back(['banana', 'cherry'], 'kiwi') AS array_push_back,
    array_push_front(['banana', 'cherry'], 'kiwi') AS array_push_front;

Output:

+------------------------+------------------------+
| array_push_back | array_push_front |
+------------------------+------------------------+
| [banana, cherry, kiwi] | [kiwi, banana, cherry] |
+------------------------+------------------------+