BUG #12553: Altering search_path between function calls - Mailing list pgsql-bugs

From rs@plusw.de
Subject BUG #12553: Altering search_path between function calls
Date
Msg-id 20150114232013.2504.41170@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #12553: Altering search_path between function calls  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-bugs by date:

Previous
From: 16blackwood16@gmail.com
Date:
Subject: BUG #12548: I cannot connect to database
Next
From: Tom Lane
Date:
Subject: Re: BUG #12553: Altering search_path between function calls