Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n7Dr4-0004cI-A0 for pgsql-general@arkaria.postgresql.org; Tue, 11 Jan 2022 09:54:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Dr2-00067R-UN for pgsql-general@arkaria.postgresql.org; Tue, 11 Jan 2022 09:54:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n7Dr2-00067I-FY for pgsql-general@lists.postgresql.org; Tue, 11 Jan 2022 09:54:12 +0000 Received: from smtp-outgoing-1701.laposte.net ([160.92.124.99]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n7Dqy-0001bC-Az for pgsql-general@postgresql.org; Tue, 11 Jan 2022 09:54:12 +0000 X-mail-filterd: {"version":"1.3.4","queueID":"4JY5cm4054z14K0g","contextId":"39e329ad-9bf1-47bc-bb2a-06bbe3760d57"} Received: from outgoing-mail.laposte.net (localhost.localdomain [127.0.0.1]) by mlpnf0109.laposte.net (SMTP Server) with ESMTP id 4JY5cm4054z14K0g for ; Tue, 11 Jan 2022 10:54:00 +0100 (CET) X-mail-filterd: {"version":"1.3.4","queueID":"4JY5cm3Czlz14K0Z","contextId":"96b6218e-fac9-4ffe-8de0-b649da8a1cc5"} X-lpn-mailing: LEGIT X-lpn-spamrating: 40 X-lpn-spamlevel: not-spam X-lpn-spamcause: OK, (0)(0000)gggruggvucftvghtrhhoucdtuddrgedvuddrudehfedgtdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecunfetrffquffvgfdpggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhfhrvffkufggtghisegrtdgssgdttdejnecuhfhrohhmpegsvghnjhdruggvvheslhgrphhoshhtvgdrnhgvthenucggtffrrghtthgvrhhnpeekheeglefgfeeggefhgeejgeffvdejkeekleekhfehvedvleehheffueefhfdtgeenucffohhmrghinhepshhtrggtkhgvgigthhgrnhhgvgdrtghomhdpphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeekuddrkedtrdegfedrvdegtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekuddrkedtrdegfedrvdegtddphhgvlhhopeiflhhpnhhftddvtdekrdhshihsrdhmvghshhgtohhrvgdrnhgvthdpmhgrihhlfhhrohhmpegsvghnjhdruggvvheslhgrphhoshhtvgdrnhgvthdprhgtphhtthhopehpghhsqhhlqdhgvghnvghrrghlsehpohhsthhgrhgvshhqlhdrohhrghdpmhhouggvpehsmhhtphhouhht Received: from wlpnf0208.sys.meshcore.net (wlpnf0208.sys.meshcore.net [81.80.43.240]) by mlpnf0109.laposte.net (SMTP Server) with ESMTPA id 4JY5cm3Czlz14K0Z for ; Tue, 11 Jan 2022 10:54:00 +0100 (CET) Date: Tue, 11 Jan 2022 10:54:00 +0100 (CET) From: benj.dev@laposte.net Reply-To: benj.dev@laposte.net To: pgsql-general@postgresql.org Message-ID: <617527791.607206.1641894840385@wlpnf0208> Subject: plpgsql function problem whith creating temp table - not correctly using search_path ? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_607205_518622910.1641894840384" X-ORIGINATING-IP: 81.80.43.240 X-Wum-Nature: EMAIL-NATURE X-SAVECOPY: true X-WUM-FROM: |~| X-WUM-TO: |~| X-WUM-REPLYTO: |~| DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=laposte.net; s=lpn-wlmd; t=1641894847; bh=IMmYlCRm8iaMRgGreY3eZnSZGQpADN1JW9/OnTndrGQ=; h=Date:From:Reply-To:To:Message-ID:Subject:MIME-Version:Content-Type; b=TD28jeODHA9835pHjsiOsZDdr+yCksPpJDu8Hq3KnsDsQEDmoN2LMvAYOoMyQRJWMyPJNIk8qUITnOVWBC2qH1gc3b+s12p6TfXEBxZ3SjUFP0sDysLyjTxOmf0yWqS1yS99RPsICZTAbHx7dh5rlZJbTUreuJ81CKHYQe0YkVjrFnNB34Lb3iaI1LVy55RsRLWcSlt3BAorOwVM1S1fwjfCYxc3Y530MFSSyCiFf2yTW2ukvOKxqCWg2MBmmLW3meivZUKg7Qr+RjQ4xrCzoyXd5h3PjtKIPECEDlcTpwlSgFD58WbUFCpRW9tXqi7fzYGQS4jq5s7w7aDiBesEhw==; List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------=_Part_607205_518622910.1641894840384 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, I would like to submit a problem (bug ?) that I encountered while handling = temporary tables in plpgsql functions. First, if I create a TABLE and a TEMP TABLE with the same name, and I reque= st without specified the schema, the temporary table is used. -- SHOW search_path; -- =3D> "$user", public -- Exectute next commands in the same transaction /* D=C3=A9but Transaction 1 */ DROP TABLE IF EXISTS public.myexemple; DROP TABLE IF EXISTS pg_temp.myexemple; CREATE TABLE IF NOT EXISTS myexemple(i INT); CREATE TEMP TABLE IF NOT EXISTS myexemple(i INT) ON COMMIT DROP; INSERT INTO public.myexemple VALUES(1); INSERT INTO public.myexemple VALUES(2); INSERT INTO public.myexemple VALUES(3); INSERT INTO myexemple VALUES(7); SELECT 'public', * FROM public.myexemple =C2=A0UNION ALL SELECT 'noschema', * FROM myexemple =C2=A0UNION ALL SELECT 'pg_temp', * FROM pg_temp.myexemple; /* Fin Transaction 1 */ =3D> public;1 public;2 public;3 noschema;7 pg_temp;7 Here, all is fine It's the expected behavior. But If I create the the TEMP TABLE in a function, it's (sometimes) the publ= ic table which is used and not the temporary table. CREATE OR REPLACE FUNCTION test_search_path_v1(tmp boolean) =C2=A0=C2=A0=C2=A0 RETURNS TABLE(ori text, i int) =C2=A0=C2=A0=C2=A0 LANGUAGE plpgsql =C2=A0=C2=A0=C2=A0 AS $_$ DECLARE =C2=A0=C2=A0=C2=A0 txt text; BEGIN =C2=A0 CREATE TEMP TABLE IF NOT EXISTS return_table(ori TEXT, i INT) ON COM= MIT DROP; =C2=A0 =C2=A0 IF $1 THEN =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CREATE TEMP TABLE IF NOT EXISTS my_table(i I= NT) ON COMMIT DROP; =C2=A0 ELSE =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CREATE TABLE IF NOT EXISTS my_table(i INT);= =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0 END IF; =C2=A0 SELECT setting FROM pg_settings WHERE name =3D 'search_path' INTO tx= t; =C2=A0 RAISE INFO 'search_path =3D %', txt; =C2=A0 =C2=A0 INSERT INTO my_table VALUES((random() * 100)::INT); =C2=A0 FOR txt IN SELECT schemaname FROM pg_tables WHERE tablename =3D 'my_= table' LOOP =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 RAISE INFO '=3D=3D> %', txt; =C2=A0 END LOOP; =C2=A0 =C2=A0 IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname =3D'public' AND = tablename =3D 'my_table') THEN =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 RAISE INFO 'public.my_table exists'; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 INSERT INTO return_table SELECT 'public', t.= i FROM public.my_table t; =C2=A0 END IF; =C2=A0 =C2=A0 IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname LIKE 'pg_temp%' = AND tablename =3D 'my_table') THEN =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 RAISE INFO 'pg_temp.my_table exists'; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 INSERT INTO return_table SELECT 'pg_temp', t= .i FROM pg_temp.my_table t; =C2=A0 END IF; =C2=A0 =C2=A0 INSERT INTO return_table SELECT '', t.i FROM my_table t; =C2=A0 RETURN QUERY SELECT t.ori, t.i FROM return_table t; END; $_$; SHOW search_path -- =3D> "$user", public; DROP TABLE IF EXISTS my_table; -- Executing each row on differents transactions but in the same session /*Session A - Transaction 1*/ SELECT * FROM test_search_path_v1(true);=C2= =A0 -- =3D> OK takes table from pg_temp (no existing table in public) /*Session A - Transaction 2*/ SELECT * FROM test_search_path_v1(false); -- = =3D> OK takes table from public /*Session A - Transaction 3*/ SELECT * FROM test_search_path_v1(true);=C2= =A0 -- =3D> OK takes table from pg_temp (and the existing from public) /*Session A - Transaction 4*/ SELECT * FROM test_search_path_v1(false); -- = =3D> OK takes table from public /*Session A - Transaction 5*/ SELECT * FROM test_search_path_v1(true);=C2= =A0 -- =3D> NOK =3D> it takes public and not pg_temp In fact, if I call 0 or 1 time "test_search_path_v1(false)" all the call wi= th "true" will be ok. But AFTER the second call with false, all subsequent call with true will fa= iled =3D> using public instead of pg_temp for the INSERT INTO my_table VALUES((r= andom() * 100)::INT) If I do the test with changing session before exh call, the problem doesn't= appear -- Executing each row on differents session /*Session A */ SELECT * FROM test_search_path_v1(true);=C2=A0 -- =3D> OK ta= kes table from pg_temp (no existing table in public) /*Session B */ SELECT * FROM test_search_path_v1(false); -- =3D> OK takes t= able from public /*Session C */ SELECT * FROM test_search_path_v1(true);=C2=A0 -- =3D> OK ta= kes table from pg_temp (and the existing from public) /*Session D */ SELECT * FROM test_search_path_v1(false); -- =3D> OK takes t= able from public /*Session E */ SELECT * FROM test_search_path_v1(true);=C2=A0 -- =3D> OK ta= kes table from pg_temp (and the existing from public) It's possible to bypass te problem with enforce the use of pg_temp like in = this second version. CREATE OR REPLACE FUNCTION test_search_path_v2(tmp boolean) RETURNS table(o= ri text, i int) =C2=A0=C2=A0=C2=A0 LANGUAGE plpgsql =C2=A0=C2=A0=C2=A0 AS $_$ DECLARE =C2=A0=C2=A0=C2=A0 txt text; BEGIN =C2=A0 CREATE TEMP TABLE IF NOT EXISTS return_table(ori TEXT, i INT) ON COM= MIT DROP; =C2=A0 =C2=A0 IF $1 THEN =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 PERFORM set_config('search_path', 'pg_temp, = "$user", public', true); -- is_local =3D true =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CREATE TEMP TABLE IF NOT EXISTS my_table(i I= NT) ON COMMIT DROP; =C2=A0 ELSE =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 PERFORM set_config('search_path', '"$user", = public', true); -- is_local =3D true =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CREATE TABLE IF NOT EXISTS my_table(i INT);= =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0 END IF; =C2=A0 SELECT setting FROM pg_settings WHERE name =3D 'search_path' INTO tx= t; =C2=A0 RAISE INFO 'search_path =3D %', txt; =C2=A0 =C2=A0 INSERT INTO my_table VALUES((random() * 100)::INT); =C2=A0 FOR txt IN SELECT schemaname FROM pg_tables WHERE tablename =3D 'my_= table' LOOP =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 RAISE INFO '=3D=3D> %', txt; =C2=A0 END LOOP; =C2=A0 IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname LIKE 'pg_temp%' = AND tablename =3D 'my_table') THEN =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 RAISE INFO 'pg_temp.my_table exists'; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 INSERT INTO return_table SELECT 'pg_temp', t= .i FROM pg_temp.my_table t; =C2=A0 END IF; =C2=A0 =C2=A0 IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname =3D'public' AND = tablename =3D 'my_table') THEN =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 RAISE INFO 'public.my_table exists'; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 INSERT INTO return_table SELECT 'public', t.= i FROM public.my_table t; =C2=A0 END IF; =C2=A0=C2=A0 =C2=A0 =C2=A0 INSERT INTO return_table SELECT '', t.i FROM my_table t; =C2=A0 RETURN QUERY SELECT t.ori, t.i FROM return_table t; END; $_$; SHOW search_path -- =3D> "$user", public DROP TABLE IF EXISTS my_table -- Executing each row on differents transactions but in the same session /*Session A - Transaction 1*/ SELECT * FROM test_search_path_v1(true);=C2= =A0 -- =3D> OK takes table from pg_temp (no existing table in public) /*Session A - Transaction 2*/ SELECT * FROM test_search_path_v1(false); -- = =3D> OK takes table from public /*Session A - Transaction 3*/ SELECT * FROM test_search_path_v1(true);=C2= =A0 -- =3D> OK takes table from pg_temp (and the existing from public) /*Session A - Transaction 4*/ SELECT * FROM test_search_path_v1(false); -- = =3D> OK takes table from public /*Session A - Transaction 5*/ SELECT * FROM test_search_path_v1(true);=C2= =A0 -- =3D> OK takes table from pg_temp (and the existing from public) =C2=A0 SELECT version() -- PostgreSQL 12.9 (Ubuntu 12.9-0ubuntu0.20.04.1) on x86_6= 4-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bi= t I can bypass but I would like to understand what is the cause of this probl= em to avoid unexpected problems. I don't understand why the probleme appears afters some (two) calls that wo= rks with public table and not everytime. I don't understand why I need to explicit pg_temp in first choice of search= _path. I thought that is the default behavior. I don't understant why there may be a difference between case in different = session and case in same session. Is the problem linked with the reuse of n= umber of pg_temp_X ? I have searched and found a thread with similarity https://dba.stackexchange.com/questions/60997/is-this-temp-table-behaviour-= documented relied on https://www.postgresql.org/message-id/20140315165011.20722.74795@wrigleys.p= ostgresql.org but in this case the problem is between SQL VS PLPGSQL and it seems to demo= nstrate that in PLPGSQL the normal attemps is to use pg_temp first. Thanks for yours helps, Regards, =C2=A0 ------=_Part_607205_518622910.1641894840384 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi,

I would like to submit a problem (bug ?) that I encountered while handling = temporary tables in plpgsql functions.

First, if I create a TABLE and a TEMP TABLE with the same name, and I reque= st without specified the schema, the temporary table is used.

-- SHOW search_path; -- =3D> "$user", public
-- Exectute next commands in the same transaction
/* D=C3=A9but Transaction 1 */
DROP TABLE IF EXISTS public.myexemple;
DROP TABLE IF EXISTS pg_temp.myexemple;
CREATE TABLE IF NOT EXISTS myexemple(i INT);
CREATE TEMP TABLE IF NOT EXISTS myexemple(i INT) ON COMMIT DROP;
INSERT INTO public.myexemple VALUES(1);
INSERT INTO public.myexemple VALUES(2);
INSERT INTO public.myexemple VALUES(3);
INSERT INTO myexemple VALUES(7);
SELECT 'public', * FROM public.myexemple
 UNION ALL SELECT 'noschema', * FROM myexemple
 UNION ALL SELECT 'pg_temp', * FROM pg_temp.myexemple;
/* Fin Transaction 1 */
=3D>
public;1
public;2
public;3
noschema;7
pg_temp;7

Here, all is fine It's the expected behavior.

But If I create the the TEMP TABLE in a function, it's (sometimes) the publ= ic table which is used and not the temporary table.

CREATE OR REPLACE FUNCTION test_search_path_v1(tmp boolean)
    RETURNS TABLE(ori text, i int)
    LANGUAGE plpgsql
    AS $_$
DECLARE
    txt text;
BEGIN
  CREATE TEMP TABLE IF NOT EXISTS return_table(ori TEXT, i INT) ON COM= MIT DROP;
 
  IF $1 THEN
      CREATE TEMP TABLE IF NOT EXISTS my_table(i I= NT) ON COMMIT DROP;
  ELSE
      CREATE TABLE IF NOT EXISTS my_table(i INT);&= nbsp;     
  END IF;

  SELECT setting FROM pg_settings WHERE name =3D 'search_path' INTO tx= t;
  RAISE INFO 'search_path =3D %', txt;
 
  INSERT INTO my_table VALUES((random() * 100)::INT);

  FOR txt IN SELECT schemaname FROM pg_tables WHERE tablename =3D 'my_= table' LOOP
      RAISE INFO '=3D=3D> %', txt;
  END LOOP;
 
  IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname =3D'public' AND = tablename =3D 'my_table') THEN
      RAISE INFO 'public.my_table exists';
      INSERT INTO return_table SELECT 'public', t.= i FROM public.my_table t;
  END IF;
 
  IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname LIKE 'pg_temp%' = AND tablename =3D 'my_table') THEN
      RAISE INFO 'pg_temp.my_table exists';
      INSERT INTO return_table SELECT 'pg_temp', t= .i FROM pg_temp.my_table t;
  END IF;
 
  INSERT INTO return_table SELECT '', t.i FROM my_table t;
  RETURN QUERY SELECT t.ori, t.i FROM return_table t;
END;
$_$;

SHOW search_path -- =3D> "$user", public;
DROP TABLE IF EXISTS my_table;
-- Executing each row on differents transactions but in the same session /*Session A - Transaction 1*/ SELECT * FROM test_search_path_v1(true); = ; -- =3D> OK takes table from pg_temp (no existing table in public)
/*Session A - Transaction 2*/ SELECT * FROM test_search_path_v1(false); -- = =3D> OK takes table from public
/*Session A - Transaction 3*/ SELECT * FROM test_search_path_v1(true); = ; -- =3D> OK takes table from pg_temp (and the existing from public)
/*Session A - Transaction 4*/ SELECT * FROM test_search_path_v1(false); -- = =3D> OK takes table from public
/*Session A - Transaction 5*/ SELECT * FROM test_search_path_v1(true); = ; -- =3D> NOK =3D> it takes public and not pg_temp


In fact, if I call 0 or 1 time "test_search_path_v1(false)" all the call wi= th "true" will be ok.
But AFTER the second call with false, all subsequent call with true will fa= iled
=3D> using public instead of pg_temp for the INSERT INTO my_table VALUES= ((random() * 100)::INT)

If I do the test with changing session before exh call, the problem doesn't= appear
-- Executing each row on differents session
/*Session A */ SELECT * FROM test_search_path_v1(true);  -- =3D> OK= takes table from pg_temp (no existing table in public)
/*Session B */ SELECT * FROM test_search_path_v1(false); -- =3D> OK take= s table from public
/*Session C */ SELECT * FROM test_search_path_v1(true);  -- =3D> OK= takes table from pg_temp (and the existing from public)
/*Session D */ SELECT * FROM test_search_path_v1(false); -- =3D> OK take= s table from public
/*Session E */ SELECT * FROM test_search_path_v1(true);  -- =3D> OK= takes table from pg_temp (and the existing from public)


It's possible to bypass te problem with enforce the use of pg_temp like in = this second version.

CREATE OR REPLACE FUNCTION test_search_path_v2(tmp boolean) RETURNS table(o= ri text, i int)
    LANGUAGE plpgsql
    AS $_$
DECLARE
    txt text;
BEGIN
  CREATE TEMP TABLE IF NOT EXISTS return_table(ori TEXT, i INT) ON COM= MIT DROP;
 
  IF $1 THEN
      PERFORM set_config('search_path', 'pg_temp, = "$user", public', true); -- is_local =3D true
      CREATE TEMP TABLE IF NOT EXISTS my_table(i I= NT) ON COMMIT DROP;
  ELSE
      PERFORM set_config('search_path', '"$user", = public', true); -- is_local =3D true
      CREATE TABLE IF NOT EXISTS my_table(i INT);&= nbsp;     
  END IF;

  SELECT setting FROM pg_settings WHERE name =3D 'search_path' INTO tx= t;
  RAISE INFO 'search_path =3D %', txt;
 
  INSERT INTO my_table VALUES((random() * 100)::INT);

  FOR txt IN SELECT schemaname FROM pg_tables WHERE tablename =3D 'my_= table' LOOP
      RAISE INFO '=3D=3D> %', txt;
  END LOOP;

  IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname LIKE 'pg_temp%' = AND tablename =3D 'my_table') THEN
      RAISE INFO 'pg_temp.my_table exists';
      INSERT INTO return_table SELECT 'pg_temp', t= .i FROM pg_temp.my_table t;
  END IF;
 
  IF EXISTS (SELECT 1 FROM pg_tables WHERE schemaname =3D'public' AND = tablename =3D 'my_table') THEN
      RAISE INFO 'public.my_table exists';
      INSERT INTO return_table SELECT 'public', t.= i FROM public.my_table t;
  END IF;
    
  INSERT INTO return_table SELECT '', t.i FROM my_table t;
  RETURN QUERY SELECT t.ori, t.i FROM return_table t;
END;
$_$;

SHOW search_path -- =3D> "$user", public
DROP TABLE IF EXISTS my_table
-- Executing each row on differents transactions but in the same session /*Session A - Transaction 1*/ SELECT * FROM test_search_path_v1(true); = ; -- =3D> OK takes table from pg_temp (no existing table in public)
/*Session A - Transaction 2*/ SELECT * FROM test_search_path_v1(false); -- = =3D> OK takes table from public
/*Session A - Transaction 3*/ SELECT * FROM test_search_path_v1(true); = ; -- =3D> OK takes table from pg_temp (and the existing from public)
/*Session A - Transaction 4*/ SELECT * FROM test_search_path_v1(false); -- = =3D> OK takes table from public
/*Session A - Transaction 5*/ SELECT * FROM test_search_path_v1(true); = ; -- =3D> OK takes table from pg_temp (and the existing from public)
 
SELECT version() -- PostgreSQL 12.9 (Ubuntu 12.9-0ubuntu0.20.04.1) on x86_6= 4-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bi= t

I can bypass but I would like to understand what is the cause of this probl= em to avoid unexpected problems.
I don't understand why the probleme appears afters some (two) calls that wo= rks with public table and not everytime.
I don't understand why I need to explicit pg_temp in first choice of search= _path. I thought that is the default behavior.
I don't understant why there may be a difference between case in different = session and case in same session. Is the problem linked with the reuse of n= umber of pg_temp_X ?

I have searched and found a thread with similarity
https://dba.stackexchange.com/questions/60997/is-this-temp-table-behaviour-= documented
relied on
https://www.postgresql.org/message-id/20140315165011.20722.74795@wrigleys.p= ostgresql.org
but in this case the problem is between SQL VS PLPGSQL and it seems to demo= nstrate that in PLPGSQL the normal attemps is to use pg_temp first.

Thanks for yours helps,
Regards,

  ------=_Part_607205_518622910.1641894840384--