BUG #15060: Row in table not found when using pg function in anexpression
От | PG Bug reporting form |
---|---|
Тема | BUG #15060: Row in table not found when using pg function in anexpression |
Дата | |
Msg-id | 151844034484.1446.1721073839109092583@wrigleys.postgresql.org обсуждение исходный текст |
Ответы |
Re: BUG #15060: Row in table not found when using pg function in anexpression
Re: BUG #15060: Row in table not found when using pg function in an expression |
Список | pgsql-bugs |
The following bug has been logged on the website: Bug reference: 15060 Logged by: Dejan Petrovic Email address: dejan.petrovic@islonline.com PostgreSQL version: 10.2 Operating system: CentOS 6 Description: Hello, I tested this in postgresql versions 9.1, 10.1 and 10.2 on centOS. In short this is what happens (in a plpgsql function): 1.) An insert is done into 'bug' table 2.) A SELECT is done to make sure the INSERT was successful 3.) Another function (get_bug_id) is called which returns id based on value. When the function is called directly, it returns the id correctly. When it's called in an expression, it does not find the inserted row and an exception is raised. I have prepared a minimal example: CREATE TABLE public.bug ( id integer NOT NULL, text text, CONSTRAINT bug_pkey PRIMARY KEY (id) ) WITH ( OIDS=FALSE ); ALTER TABLE public.bug OWNER TO postgres; CREATE OR REPLACE FUNCTION public.get_bug_id(in_text text) RETURNS integer AS $BODY$ DECLARE my_int int; BEGIN SELECT INTO my_int id from bug WHERE text = in_text; IF NOT FOUND THEN RAISE EXCEPTION 'row not found - BUG?'; END IF; RETURN my_int; END; $BODY$ LANGUAGE plpgsql STABLE COST 100; ALTER FUNCTION public.get_bug_id(text) OWNER TO postgres; CREATE OR REPLACE FUNCTION test_bug() RETURNS text AS $BODY$ DECLARE my_int int; my_text text; BEGIN my_text := 'this is a bug'; INSERT INTO bug (id,text) VALUES (1,my_text); SELECT INTO my_int id from bug WHERE text = my_text; IF NOT FOUND THEN RAISE EXCEPTION 'row does not exist'; END IF; perform get_bug_id(my_text); -- This is OK - get_bug_id returns '1' perform id FROM bug WHERE id = get_bug_id(my_text); -- This fails - get_bug_id raises exception in version 10, works OK in version 9.1 RETURN 'OK'; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; ALTER FUNCTION test_bug() OWNER TO postgres; select test_bug()
В списке pgsql-bugs по дате отправления: