Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PSQL Error: function does not exist

Tags:

postgresql

I have made a function in postgres

CREATE OR REPLACE FUNCTION foobar(
    x TEXT,
    y TEXT,
    z REAL
) RETURNS BOOLEAN AS $func$
.
.
.
$func$ LANGUAGE plpgsql;

When I do \df i get the following:

+----------+--------+------------------+------------------------+---------+
|  Schema  |  Name  | Result data type |  Argument data types   |  Type   |
+----------+--------+------------------+------------------------+---------+
| mySchema | foobar | boolean          | x text, y text, z real | normal  |
+----------+--------+------------------+------------------------+---------+

But when I try to use it I get [42883] ERROR: function foobar(text, text, real) does not exist. Hint: No function matches the given name and argument types. You might need to add explicit type casts. The call I'm doing is:

SELECT * FROM myTable WHERE foobar(column1::text, 'hello'::text, 7.2::real);

To me it seems like the function exists and the types match, I'm struggling to figure out what's wrong.

like image 719
guest856 Avatar asked Dec 29 '25 23:12

guest856


1 Answers

As a_horse_with_no_name mentioned in his comment, the solution is prefix the function with the schema.

Wrong:   SELECT * FROM myTable WHERE foobar(column1::text, 'hello'::text, 7.2::real);
Correct: SELECT * FROM myTable WHERE mySchema.foobar(column1::text, 'hello'::text, 7.2::real);
like image 161
guest856 Avatar answered Jan 01 '26 16:01

guest856