Search path & functions in temporary schemas

From: jose luis pillado <josel(dot)pillado(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Search path & functions in temporary schemas
Date: 2018-12-11 16:04:25
Message-ID: CAHmzsaFuuNH4CRadFtHmSuMV+MdV=4a0-PMN3FA9EdRj09gGGg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I was trying to mock a function. So I followed the instructions in this
<https://www.postgresql.org/message-id/0E379B0D-EEFA-45FB-AC60-23F760B8D338%40justatheory.com>
thread.

I created a function with the same name as the existing one in different
schema, and I updated the search path adding that schema at the beginning.

This solution worked with a real schema, but it did not with a temporary
one.

Code working with a real schema:

> SHOW SEARCH_PATH; -- public

CREATE OR REPLACE FUNCTION public.get_random_string()
> RETURNS TEXT LANGUAGE SQL AS $$
> SELECT 'real'::text;
> $$;

SELECT get_random_string(); -- real

CREATE SCHEMA mock;
> CREATE OR REPLACE FUNCTION mock.get_random_string()
> RETURNS TEXT LANGUAGE SQL AS $$
> SELECT 'mock'::text;
> $$;

SELECT get_random_string(); -- real

SET SEARCH_PATH = mock, public;
> SELECT get_random_string(); -- mock

Code not working with a temporary schema:

> SHOW SEARCH_PATH; -- public

CREATE OR REPLACE FUNCTION public.get_random_string()
> RETURNS TEXT LANGUAGE SQL AS $$
> SELECT 'real'::text;
> $$;
> SELECT get_random_string(); -- real

SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema(); --
> pg_temp_12

CREATE OR REPLACE FUNCTION pg_temp_12.get_random_string()
> RETURNS TEXT LANGUAGE SQL AS $$
> SELECT 'mock'::text;
> $$;
> SELECT get_random_string(); -- real

SET SEARCH_PATH = pg_temp_12, public;
> SELECT get_random_string(); -- real

Is there any way to make this work?

Thanks,
Jose

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Olarte 2018-12-11 16:07:48 Fwd: Code for getting particular day of week number from month
Previous Message Adrian Klaver 2018-12-11 15:46:51 Re: Newly Created Source DB Table Not Reflecting into Destination Foreign Tables