Fix “No function matches the given name and argument types ‘bool_and(INTEGER)'” in DuckDB

If you’re getting an error that reads something like “No function matches the given name and argument types ‘bool_and(INTEGER)’” in DuckDB, it’s probably because you’re passing a non-boolean value to the bool_and() function.

The bool_and() function is for use against boolean expressions, so to fix this issue, be sure that the argument you pass to the function is a boolean expression.

Example of Error

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

SELECT bool_and(1);

Output:

Binder Error: No function matches the given name and argument types 'bool_and(INTEGER)'. You might need to add explicit type casts.
Candidate functions:
bool_and(BOOLEAN) -> BOOLEAN

LINE 1: SELECT bool_and(1);

Here, I passed an integer to the function, and it returned an error due to the fact that it wasn’t a boolean value.

Obviously, we wouldn’t normally pass a boolean constant like this. We might typically use this function to check data in a table.

So to demonstrate the error on table data, let’s create the following table:

-- Create table
CREATE TABLE t1 (
    c1 INTEGER,
    c2 BOOLEAN
);

-- Insert data
INSERT INTO t1 (c1, c2) VALUES ( 1, TRUE );
INSERT INTO t1 (c1, c2) VALUES ( 2, FALSE );
INSERT INTO t1 (c1, c2) VALUES ( 3, TRUE );

-- Select all data
SELECT * FROM t1;

Output:

+----+-------+
| c1 | c2 |
+----+-------+
| 1 | true |
| 2 | false |
| 3 | true |
+----+-------+

Now let’s run the bool_and() function against that table, but we’ll run it against the wrong column:

SELECT bool_and(c1) FROM t1;

Output:

Binder Error: No function matches the given name and argument types 'bool_and(INTEGER)'. You might need to add explicit type casts.
Candidate functions:
bool_and(BOOLEAN) -> BOOLEAN

LINE 1: SELECT bool_and(c1) FROM t1;

Once again we got the error.

Solution

To fix this issue, be sure to pass a boolean expression to the bool_and() function.

So to fix the first example above, we could do this:

SELECT bool_and(TRUE);

Output:

+--------------------------------+
| bool_and(CAST('t' AS BOOLEAN)) |
+--------------------------------+
| true |
+--------------------------------+

This time it ran without error.

Let’s fix the second example:

SELECT bool_and(c2) FROM t1;

Output:

+--------------+
| bool_and(c2) |
+--------------+
| false |
+--------------+

This time it ran without error. In this case all I did was pass the c2 column (which is a boolean column) instead of the column from c1 (which is an integer column).