Re: "Type does not exist" error when returning array of type in non-public schema - Mailing list pgsql-hackers

From Chapman Flack
Subject Re: "Type does not exist" error when returning array of type in non-public schema
Date
Msg-id 67A4EC94.6070700@acm.org
Whole thread Raw
In response to "Type does not exist" error when returning array of type in non-public schema  (Chris Cleveland <ccleveland@dieselpoint.com>)
List pgsql-hackers
Hi,

On 02/06/25 11:46, Chris Cleveland wrote:
> I'm developing a Postgres extension that gets installed in its own schema,
> "rdb". It creates its own type, "token", and has a function that returns an
> array of that type. When I SELECT the function in psql, I get an ERROR:
> type "token" does not exist
> ...
> this fails:
> 
> CREATE FUNCTION my_func ... RETURNS Token[] ...

If I'm reading your description right, are you saying rather that the
CREATE FUNCTION (within the extension script) does not fail, but that
the failure is seen later when the function is used in a query?

Is the function implemented in LANGUAGE sql or in some other procedural
language?

If it is in LANGUAGE sql, is it written in the SQL standard form with
BEGIN ATOMIC, or in the PostgreSQL form where the function body is all
in a string literal?

In the SQL standard form, it would have the token type resolved at
function creation time, and not need to rely on the search path at
time of use.

In the string literal form, there could be a use of the type within
the body of your function that is not qualified by its schema name.
That's what would need to be fixed, not the RETURNS declaration of
CREATE FUNCTION.

You could change Token[] to rdb.Token[] wherever it appears in the
string literal, or add a SET search_path clause to the CREATE FUNCTION
itself, ensuring that the needed schema is on the path.

Regards,
-Chap



pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: "Type does not exist" error when returning array of type in non-public schema
Next
From: Jeff Davis
Date:
Subject: Re: new commitfest transition guidance