pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

SET search_path not showing correct on plan or apply if you use ''

Open silentworks opened this issue 8 months ago • 2 comments

When I create a function and set the search_path to '' and then run the plan I see the output showing search_path with "" instead. When I run the apply this fails as that is the wrong delimiter to use. It also seems like the namespaces aren't qualifying too when I set the search_path to say pg_temp, the namespaces get stripped from the function.

Table creation snippet:

create table public.test (
  id bigint generated by default as identity not null,
  title text null,
  created_at timestamp with time zone not null default now(),
  constraint test_pkey primary key (id)
);

Here is an example function:

CREATE OR REPLACE FUNCTION create_hello(p_title text)
LANGUAGE plpgsql
SECURITY INVOKER
SET search_path = ''
AS $$
BEGIN
  INSERT INTO public.test (title) VALUES (p_title)
  RETURNING id;
END;
$$;

I am expecting the example function to remain as it is with '' for the value of search_path, but instead it is showing as:

CREATE OR REPLACE FUNCTION create_hello(p_title text)
LANGUAGE plpgsql
SECURITY INVOKER
SET search_path = ""
AS $$
BEGIN
  INSERT INTO test (title) VALUES (p_title)
  RETURNING id;
END;
$$;

after a plan or apply.

edit: updated the snippet to remove public. from test in the current output.

silentworks avatar Mar 09 '26 15:03 silentworks

Why do you want to set the search_path to ''

tianzhou avatar Mar 09 '26 15:03 tianzhou

Because I don't want to set it to a particular schema and Postgres allows this. Also note that the Supabase docs recommend folks to do this too which would make this problematic with users using Supabase. The other issue here however is that even if I was to set the search_path to say pg_catalog, pg_temp and then try to use the full namespace inside of my function like public.test, the output from plan or apply is only showing test without the public.schema. I think this is a bigger issue here.

silentworks avatar Mar 09 '26 16:03 silentworks