pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: px812@mailbox.org
Subject: BUG #15906: Insert ops within a branch of "RETURN QUERY WITH"  are not seen by a subsequent SELECT
Date: Sat, 13 Jul 2019 08:37:47 +0000
Message-ID: <15906-d64845e69b79f9dd@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15906
Logged by:          Hugo Mildenberger
Email address:      px812@mailbox.org
PostgreSQL version: 11.4
Operating system:   Gentoo Linux
Description:        

--  13.2.1. Read Committed Isolation Level
--   
--  [...] However, SELECT does see the effects of previous updates executed
within 
--        its own transaction, even though they are not yet committed.
[...]
--  Source: https://www.postgresql.org/docs/11/transaction-iso.html

--  Assuming the term "previous updates" as cited above also includes insert
operations, the 
--  following example shows that SELECT actually does NOT see uncommitted
data within 
--  its own transaction.

CREATE TABLE xtmp( name TEXT);

CREATE OR REPLACE FUNCTION itest1( aName Text) RETURNS SETOF xtmp AS $$
BEGIN
   RETURN QUERY
     WITH ix AS ( 
          INSERT INTO xtmp(name) VALUES(aName) RETURNING *
     ) SELECT * FROM xtmp WHERE name = (SELECT name from ix);
--    Same result as with 
--     ) SELECT * FROM xtmp;  
--     ) SELECT * FROM xtmp WHERE name = aName;
END
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION itest2( aName Text) RETURNS SETOF xtmp AS $$
BEGIN
   INSERT INTO xtmp(name) VALUES(aName);
   RETURN QUERY  SELECT * FROM xtmp WHERE name = aName;
END
$$ LANGUAGE plpgsql;

--  Test log:
--
--  opk=# begin;
--  opk=# select * from itest1('hello');
--  name
--  ------
--  (0 rows)
--
--  opk=# select * from itest1('hello');
--  name
--  -------
--  hello
--  (1 row)
-- 
--  opk=# select * from xtmp;
--  name
--  -------
--  hello
--  hello
--  (2 rows)
--
--  opk=# commit;
--
--  opk=# delete from xtmp;
--  DELETE 2
--
--  opk=# begin;
--  opk=# select * from itest2('hello');
--  name
--  -------
--  hello
--  (1 row)
--
--  opk=# select * from itest2('hello');
--  name
--  -------
--  hello
--  hello
--  (2 rows)
--
--  opk=# select * from xtmp;
--  name
--  -------
--  hello
--  hello
--  (2 rows)
--
--  opk=# commit;



view thread (2+ messages)  latest in thread

Message-ID: <15906-d64845e69b79f9dd@postgresql.org>
Permalink:  ../15906-d64845e69b79f9dd@postgresql.org/
Also on:    postgresql.org/message-id/15906-d64845e69b79f9dd@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: noreply@postgresql.org, px812@mailbox.org
  Subject: Re: BUG #15906: Insert ops within a branch of "RETURN QUERY WITH"  are not seen by a subsequent SELECT
  In-Reply-To: <15906-d64845e69b79f9dd@postgresql.org>
  References: <15906-d64845e69b79f9dd@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