pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Winanjaya Amijoyo <winanjaya.amijoyo@gmail.com>
Cc: David Rowley <david.rowley@2ndquadrant.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Returning empty on insert
Date: Thu, 16 May 2019 07:51:37 -0700
Message-ID: <f4e2e726-cb07-9b59-0692-b040be032bf2@aklaver.com> (raw)
In-Reply-To: <CAAHo4LNoRwb_Hoa2L0ciuJrSBRVWppfi+df6MFz1YJs6v2eUGg@mail.gmail.com>
References: <CAAHo4LNFA7F+PKTqq5dEbWaDzjEe8z=G9K7ky4YWyDxTV04A-A@mail.gmail.com>
	<CAKJS1f_r+J+GeAxRsdrDtNcqA1shCcQbORh4iysiAA2GTFSPHA@mail.gmail.com>
	<CAAHo4LMCxNxW2O-C+DL6a_gRGy2i8k=ic3KartDuNvWDQZ+9wQ@mail.gmail.com>
	<CAKJS1f9CitKTCObBCs2c8qhfJsX9xYG4MRvB+Mmd=u90oizyaA@mail.gmail.com>
	<CAAHo4LPZz-4ft5DQzTjKN=0Ywqer604iqUZpcjCWk-kR2Ye+6w@mail.gmail.com>
	<CAKJS1f9Nzqn4LzBTSFAeFmQfJF5mxDUqhk-oP9=N9u92J4-7gw@mail.gmail.com>
	<CAAHo4LPMQC7SzqWX7SJQ_0PKf5DKhOQ6Nvfuso2_fbvcvPdxAA@mail.gmail.com>
	<68a33e60-96ef-98ab-49bd-1c5ad9c72ecc@aklaver.com>
	<CAAHo4LNoRwb_Hoa2L0ciuJrSBRVWppfi+df6MFz1YJs6v2eUGg@mail.gmail.com>

On 5/16/19 7:25 AM, Winanjaya Amijoyo wrote:
> see enclosed screenshot..
> 
> I thought, the record still locked that's why it returns empty..

I'm not sure I believe that screenshot. For one I don't know why it 
showing the area and last_update as they are not being returned?

Try the query in psql and see what happens. As an example:

update check_test set fld_1 = '67' where id =1 returning id;
  id
----
   1
(1 row)

UPDATE 1


> 
> On Thu, May 16, 2019 at 9:21 PM Adrian Klaver <adrian.klaver@aklaver.com 
> <mailto:adrian.klaver@aklaver.com>> wrote:
> 
>     On 5/16/19 7:10 AM, Winanjaya Amijoyo wrote:
>      > Hi David,
>      >
>      > thanks for your advise, as I am new with postgresql..
>      > I try to use LOCK as below, but it does not returning pid?
>      > what I missed?
> 
>     I'm not sure which pid you are referring to, the INSERT or UPDATE or
>     both?
> 
>     Can you show the output of the query?
>      >
>      > BEGIN TRANSACTION;
>      > LOCK TABLE test IN ACCESS EXCLUSIVE MODE;
>      > WITH s AS (
>      >     SELECT pid FROM test WHERE area = 'test4'
>      > ), i AS (
>      >     INSERT INTO test (area)
>      >     SELECT 'test4'
>      >     WHERE NOT EXISTS (SELECT 1 FROM s)
>      >     RETURNING pid
>      > )
>      > UPDATE area
>      > SET last_update = CURRENT_TIMESTAMP
>      > WHERE pid = (SELECT pid FROM s UNION SELECT pid FROM i)
>      > RETURNING pid;
>      > COMMIT TRANSACTION;
>      >
>      >
> 
> 
>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (15+ messages)  latest in thread

Message-ID: <f4e2e726-cb07-9b59-0692-b040be032bf2@aklaver.com>
Permalink:  ../f4e2e726-cb07-9b59-0692-b040be032bf2@aklaver.com/
Also on:    postgresql.org/message-id/f4e2e726-cb07-9b59-0692-b040be032bf2@aklaver.com

 · 

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-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, winanjaya.amijoyo@gmail.com, david.rowley@2ndquadrant.com
  Subject: Re: Returning empty on insert
  In-Reply-To: <f4e2e726-cb07-9b59-0692-b040be032bf2@aklaver.com>
  References: <CAAHo4LNFA7F+PKTqq5dEbWaDzjEe8z=G9K7ky4YWyDxTV04A-A@mail.gmail.com> <CAKJS1f_r+J+GeAxRsdrDtNcqA1shCcQbORh4iysiAA2GTFSPHA@mail.gmail.com> <CAAHo4LMCxNxW2O-C+DL6a_gRGy2i8k=ic3KartDuNvWDQZ+9wQ@mail.gmail.com> <CAKJS1f9CitKTCObBCs2c8qhfJsX9xYG4MRvB+Mmd=u90oizyaA@mail.gmail.com> <CAAHo4LPZz-4ft5DQzTjKN=0Ywqer604iqUZpcjCWk-kR2Ye+6w@mail.gmail.com> <CAKJS1f9Nzqn4LzBTSFAeFmQfJF5mxDUqhk-oP9=N9u92J4-7gw@mail.gmail.com> <CAAHo4LPMQC7SzqWX7SJQ_0PKf5DKhOQ6Nvfuso2_fbvcvPdxAA@mail.gmail.com> <68a33e60-96ef-98ab-49bd-1c5ad9c72ecc@aklaver.com> <CAAHo4LNoRwb_Hoa2L0ciuJrSBRVWppfi+df6MFz1YJs6v2eUGg@mail.gmail.com> <f4e2e726-cb07-9b59-0692-b040be032bf2@aklaver.com>

* 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