BUG in temp tables involving a temp table not properly hiding a regular table as well as allowing non-existent column names

Поиск
Список
Период
Сортировка
Искать
От
Frank van Vugt
Тема
BUG in temp tables involving a temp table not properly hiding a regular table as well as allowing non-existent column names
Дата
Msg-id
200506071806.34914.ftm.van.vugt@foxi.nl
Список
Дерево обсуждения
BUG in temp tables involving a temp table not properly hiding a regular table as well as allowing non-existent column names Frank van Vugt <ftm.van.vugt@foxi.nl>
Re: BUG in temp tables involving a temp table not properly Stephan Szabo <sszabo@megazone.bigpanda.com>
Re: BUG in temp tables involving a temp table not properly Frank van Vugt <ftm.van.vugt@foxi.nl>
L.S.

Looking forward to your analysis of the following bug:


database=# select version();
                                version
------------------------------------------------------------------------
 PostgreSQL 8.0.3 on i586-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.3
(1 row)


****
**** START HERE TO REPRODUCE
****

CREATE TYPE full_sequence_type AS (id int);
CREATE OR REPLACE FUNCTION full_sequence(integer, integer)
	RETURNS SETOF full_sequence_type
	LANGUAGE 'plpgsql'
	IMMUTABLE
	STRICT
	SECURITY INVOKER
	AS '	DECLARE
			my_from ALIAS FOR $1;
			my_to ALIAS FOR $2;
			result full_sequence_type%ROWTYPE;
		BEGIN
			-- just loop
			FOR i IN my_from..my_to LOOP
				result.id = i;
				RETURN NEXT result;
			END LOOP;

			-- finish
			RETURN;
		END;';

-- create a regular table and show that it holds 100 records
create table f1 as select id as id2 from full_sequence(1, 100);
-- show that it holds 100 records
select count(*) from f1;

-- create a regular table and show that it holds 100 records
create temp table f1 as select id as id2 from full_sequence(1, 100);
select count(*) from f1;

-- remove 99 records from the temp table and show that 1 row remains
delete from f1 where id2 > 1;
select count(*) from f1;

-- try to select a non-existent column, show that it fails
select id from f1;
ERROR:  column "id" does not exist

-- however, the following query will happily run AND return a wrong result
-- based on the regular table instead of the temporary one
select count(*) from full_sequence(1, 100) where id in (select id from f1);
 count
-------
   100
(1 row)



****
**** USE THIS TO CLEANUP
****

DROP FUNCTION full_sequence(integer, integer);
DROP TYPE full_sequence_type;
DROP TABLE f1;
DROP TABLE f1;




-- 
Best,




Frank.
В списке pgsql-bugs по дате отправления
От: Tom Lane
Дата:
От: Stephan Szabo
Дата:
FAQ