Re: Do not INSERT if UPDATE fails

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Do not INSERT if UPDATE fails
Date: 2017-08-02 16:40:31
Message-ID: CAKFQuwZn=_qwX43A+bOEcB3GVXO34nE5TJ8u6V0vRcjx7+MaKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Aug 2, 2017 at 8:58 AM, Alexander Farber <alexander(dot)farber(at)gmail(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-08-02 16:49:19 Re: Would you add a --dry-run to pg_restore?
Previous Message David G. Johnston 2017-08-02 16:37:41 Re: Would you add a --dry-run to pg_restore?