pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: gordo169@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #9505: If a function references an unqualified table, it only resolves it from search_path once per session
Date: Sun, 09 Mar 2014 21:45:04 +0000
Message-ID: <20140309214504.1230.51420@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      9505
Logged by:          Gordon Shannon
Email address:      gordo169@gmail.com
PostgreSQL version: 9.2.4
Operating system:   Centos
Description:        

After session starts, 1st time you run a function with an unqualified
schema, it will use search_path to resolve.  If in the same session you set
search_path to point to a different schema with the same table name, when
you rerun the function it still resolves to the original schema. 

** -------- TEST CASE ---------**
set search_path to default;
show search_path;

create or replace function get_count()
 returns int
 language plpgsql
as $$
declare
    v_cnt int := 0;
begin
  select count(*) into v_cnt from junk;
  return v_cnt;
end;
$$;

create schema frick;
create table frick.junk (id int);
insert into frick.junk values (1), (2);

create schema frack;
create table frack.junk (id int);
insert into frack.junk values (1), (2), (3), (4), (5);

set search_path to public, frick;
select * from get_count();
set search_path to public, frack;
select * from get_count();

\c
set search_path to public, frack;
select * from get_count();
set search_path to public, frick;
select * from get_count();


** -------- TEST CASE WITH OUTPUT---------**
[admin@dev1:acct] 15:38:05> set search_path to default;
SET
Time: 20.340 ms
[admin@dev1:acct] 15:39:21> show search_path;
  search_path   
----------------
 "$user",public
(1 row)

Time: 17.667 ms
[admin@dev1:acct] 15:39:21> 
[admin@dev1:acct] 15:39:21> create or replace function get_count()
>  returns int
>  language plpgsql
> as $$
> declare
>     v_cnt int := 0;
> begin
>   select count(*) into v_cnt from junk;
>   return v_cnt;
> end;
> $$;
CREATE FUNCTION
Time: 21.481 ms
[admin@dev1:acct] 15:39:21> 
[admin@dev1:acct] 15:39:21> create schema frick;
CREATE SCHEMA
Time: 25.057 ms
[admin@dev1:acct] 15:39:21> create table frick.junk (id int);
CREATE TABLE
Time: 19.538 ms
[admin@dev1:acct] 15:39:21> insert into frick.junk values (1), (2);
INSERT 0 2
Time: 16.467 ms
[admin@dev1:acct] 15:39:21> 
[admin@dev1:acct] 15:39:21> create schema frack;
CREATE SCHEMA
Time: 17.609 ms
[admin@dev1:acct] 15:39:21> create table frack.junk (id int);
CREATE TABLE
Time: 24.746 ms
[admin@dev1:acct] 15:39:21> insert into frack.junk values (1), (2), (3),
(4), (5);
INSERT 0 5
Time: 18.159 ms
[admin@dev1:acct] 15:39:21> 
[admin@dev1:acct] 15:39:21> set search_path to public, frick;
SET
Time: 17.433 ms
[admin@dev1:acct] 15:39:21> select * from get_count();
 get_count 
-----------
         2
(1 row)

Time: 18.490 ms
[admin@dev1:acct] 15:39:21> set search_path to public, frack;
SET
Time: 17.051 ms
[admin@dev1:acct] 15:39:21> select * from get_count();
 get_count 
-----------
         2
(1 row)

Time: 16.365 ms
[admin@dev1:acct] 15:39:21> 
[admin@dev1:acct] 15:39:21> \c
psql (9.2.1, server 9.2.6)
You are now connected to database "acct" as user "admin".
[admin@dev1:acct] 15:39:22> set search_path to public, frack;
SET
Time: 18.069 ms
[admin@dev1:acct] 15:39:22> select * from get_count();
 get_count 
-----------
         5
(1 row)

Time: 19.769 ms
[admin@dev1:acct] 15:39:22> set search_path to public, frick;
SET
Time: 16.020 ms
[admin@dev1:acct] 15:39:22> select * from get_count();
 get_count 
-----------
         5
(1 row)




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (2+ messages)  latest in thread

Message-ID: <20140309214504.1230.51420@wrigleys.postgresql.org>
Permalink:  ../20140309214504.1230.51420@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20140309214504.1230.51420@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: gordo169@gmail.com
  Subject: Re: BUG #9505: If a function references an unqualified table, it only resolves it from search_path once per session
  In-Reply-To: <20140309214504.1230.51420@wrigleys.postgresql.org>
  References: <20140309214504.1230.51420@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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