Re: Returning empty on insert

From: Winanjaya Amijoyo <winanjaya(dot)amijoyo(at)gmail(dot)com>
To: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Returning empty on insert
Date: 2019-05-16 09:13:38
Message-ID: CAAHo4LPZz-4ft5DQzTjKN=0Ywqer604iqUZpcjCWk-kR2Ye+6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

What I want to archive here is:

When record not found then insert and return pid value or if not found then
update based on pid and again return its pid.

Please help.

Many thanks in advance.

Regards
Win

On Thu, 16 May 2019 at 15.47 David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
wrote:

> On Thu, 16 May 2019 at 20:28, Winanjaya Amijoyo
> <winanjaya(dot)amijoyo(at)gmail(dot)com> wrote:
> > column pid is bigserial that I expect to return on both insert and update
> > I don't want to use ON CONFLICT since it would increasing the sequence
> although it updating the data
>
> It's not very clear what you're trying to do here.
>
> So, by "pid returns empty", you mean that the UPDATE updates 0 rows,
> and you always expect it to update 1 row? The UPDATE is going to
> update 0 rows if either "s" is an empty relation, or there's no row in
> "area" with the "pid" that's in "s". "s" will be an empty relation if
> "test" does not have any row matching WHERE area = 'test5'.
>
> --
> David Rowley http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>
--
Kind regards,
Winanjaya
———————————————-
Sent from my iPhone - Gmail MobIle.
My apologize for the typos & brevity.
———————————————-

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Rowley 2019-05-16 09:25:28 Re: Returning empty on insert
Previous Message David Rowley 2019-05-16 08:46:59 Re: Returning empty on insert