pg.ddx.io pgsql-bugs@postgresql.org mailing list archivehelp / color / mirror / Atom feed
BUG #12553: Altering search_path between function calls 2+ messages / 2 participants [nested] [flat]
* BUG #12553: Altering search_path between function calls @ 2015-01-14 23:20 rs@plusw.de 2015-01-15 00:44 ` Re: BUG #12553: Altering search_path between function calls Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: rs@plusw.de @ 2015-01-14 23:20 UTC (permalink / raw) To: pgsql-bugs The following bug has been logged on the website: Bug reference: 12553 Logged by: Rolf Schaufelberger Email address: rs@plusw.de PostgreSQL version: 9.2.4 Operating system: Ubuntu 4.4.3-4ubuntu5.1 Description: Hello, given the following setup: create schema a; create table a.company (id integer primary key , name varchar (100) ); create table a.company_objects(id serial, company_id integer references a.company(id) , obj_class varchar(100)); create schema b; create table b.company (id integer primary key , name varchar (100) ); create table b.company_objects(id serial, company_id integer references b.company(id) , obj_class varchar(100)); create or replace function public.xxx( coid integer) returns integer as $$ DECLARE newid integer; BEGIN insert into company_objects(company_id, obj_class) values (coid, 'TEST') returning id into newid; return newid; END; $$ language plpgsql; set search_path to a; insert into company values (123,'A'); set search_path to b; insert into company values (987,'B'); set search_path to a, public; select xxx(123); set search_path to b, public; select xxx(987); drop schema a cascade; drop schema b cascade; drop function public.xxx(integer); and now executing gives : (sorry messages ar in German, but I think problem could be understood anyway) CREATE SCHEMA psql:/tmp/xxx.sql:2: HINWEIS: CREATE TABLE / PRIMARY KEY erstellt implizit einen Index »company_pkey« für Tabelle »company« CREATE TABLE psql:/tmp/xxx.sql:3: HINWEIS: CREATE TABLE erstellt implizit eine Sequenz »company_objects_id_seq« für die »serial«-Spalte »company_objects.id« CREATE TABLE CREATE SCHEMA psql:/tmp/xxx.sql:6: HINWEIS: CREATE TABLE / PRIMARY KEY erstellt implizit einen Index »company_pkey« für Tabelle »company« CREATE TABLE psql:/tmp/xxx.sql:7: HINWEIS: CREATE TABLE erstellt implizit eine Sequenz »company_objects_id_seq« für die »serial«-Spalte »company_objects.id« CREATE TABLE CREATE FUNCTION SET INSERT 0 1 SET INSERT 0 1 SET xxx ----- 1 (1 Zeile) SET psql:/tmp/xxx.sql:28: FEHLER: Einfügen oder Aktualisieren in Tabelle »company_objects« verletzt Fremdschlüssel-Constraint »company_objects_company_id_fkey« DETAIL: Schlüssel (company_id)=(987) ist nicht in Tabelle »company« vorhanden. KONTEXT: SQL-Anweisung »insert into company_objects(company_id, obj_class) values (coid, 'TEST') returning id« PL/pgSQL function xxx(integer) line 3 at SQL-Anweisung psql:/tmp/xxx.sql:31: HINWEIS: Löschvorgang löscht ebenfalls 2 weitere Objekte DETAIL: Löschvorgang löscht ebenfalls Tabelle a.company Löschvorgang löscht ebenfalls Tabelle a.company_objects DROP SCHEMA psql:/tmp/xxx.sql:32: HINWEIS: Löschvorgang löscht ebenfalls 2 weitere Objekte DETAIL: Löschvorgang löscht ebenfalls Tabelle company Löschvorgang löscht ebenfalls Tabelle company_objects DROP SCHEMA DROP FUNCTION =============== so , changing the search_path between two function calls within one session doesn't seem to work. Now , is this a bug or , if not, is this behaviour documented somewhere ? Thanks for your answer and many thanks for giving us PostgreSQL ! Rolf -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #12553: Altering search_path between function calls 2015-01-14 23:20 BUG #12553: Altering search_path between function calls rs@plusw.de @ 2015-01-15 00:44 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2015-01-15 00:44 UTC (permalink / raw) To: rs@plusw.de; +Cc: pgsql-bugs rs@plusw.de writes: > Bug reference: 12553 > Logged by: Rolf Schaufelberger > Email address: rs@plusw.de > PostgreSQL version: 9.2.4 > Operating system: Ubuntu 4.4.3-4ubuntu5.1 [ this function acts funny if the search_path is changed between calls: ] > create or replace function public.xxx( coid integer) > returns integer as $$ DECLARE newid integer; > BEGIN > insert into company_objects(company_id, obj_class) values (coid, 'TEST') > returning id into newid; > return newid; > END; > $$ language plpgsql; This example works as you're expecting in 9.3 and up, as per this 9.3 release note item: Force cached plans to be replanned if the search_path changes (Tom Lane) Previously, cached plans already generated in the current session were not redone if the query was re-executed with a new search_path setting, resulting in surprising behavior. So in previous versions, the function latches onto whichever company_objects table it sees during its first execution. Although that's arguably a bug, we felt it was not safe to change the behavior so fundamentally in minor releases. 9.2.x will not get changed in this way. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2015-01-15 00:44 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2015-01-14 23:20 BUG #12553: Altering search_path between function calls rs@plusw.de 2015-01-15 00:44 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox