2
votes

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.

1
You need to prefix it with the schema: where "mySchema".foobar(...) - a_horse_with_no_name
That did the trick, thanks! - guest856
Note that a user requires the USAGE privilege on the schema (e.g. public) to execute a function. Otherwise you get a function does not exist error. - FireEmerald

1 Answers

2
votes

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);