Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WMlXu-0001eQ-2h for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Mar 2014 21:46:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WMlXt-0001Ir-Iv for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Mar 2014 21:46:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WMlXr-0001Ii-Iy for pgsql-bugs@postgresql.org; Sun, 09 Mar 2014 21:46:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WMlXn-0007c4-Sh for pgsql-bugs@postgresql.org; Sun, 09 Mar 2014 21:46:04 +0000 MIME-Version: 1.0 Subject: BUG #9505: If a function references an unqualified table, it only resolves it from search_path once per session To: pgsql-bugs@postgresql.org From: gordo169@gmail.com Date: Sun, 09 Mar 2014 21:45:04 +0000 Message-ID: <20140309214504.1230.51420@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.1 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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