Re: [GENERAL] Do not INSERT if UPDATE fails - Mailing list pgsql-general

From David G. Johnston
Subject Re: [GENERAL] Do not INSERT if UPDATE fails
Date
Msg-id CAKFQuwZn=_qwX43A+bOEcB3GVXO34nE5TJ8u6V0vRcjx7+MaKA@mail.gmail.com
Whole thread Raw
In response to [GENERAL] Do not INSERT if UPDATE fails  (Alexander Farber <alexander.farber@gmail.com>)
Responses Re: [GENERAL] Do not INSERT if UPDATE fails  (Alexander Farber <alexander.farber@gmail.com>)
List pgsql-general
On Wed, Aug 2, 2017 at 8:58 AM, Alexander Farber <alexander.farber@gmail.com> wrote:
However if the user record is not found or the user already has vip_until >= CURRENT_TIMESTAMP (i.e. the user has already purchased "vip status") I would like to cancel the INSERT.

 
​You can "join" two DDL commands by using a Common Table Expression (CTE) (i.e., WITH / SELECT)​.  You would need to make it so the UPDATE happens first and if there are no results the INSERT simply becomes a no-op.

David J.

pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: [GENERAL] Would you add a --dry-run to pg_restore?
Next
From: Tom Lane
Date:
Subject: Re: [GENERAL] Would you add a --dry-run to pg_restore?