Re: [PATCH] Implement INSERT SET syntax

From: Gareth Palmer <gareth(at)internetnz(dot)net(dot)nz>
To: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Implement INSERT SET syntax
Date: 2019-07-19 02:38:46
Message-ID: 823D82DF-70B9-4662-BBEA-ECEB72EF725D@internetnz.net.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Kyotaro,

Thank-you for looking at the patch.

> On 18/07/2019, at 6:54 PM, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> wrote:
>
> Hello.
>
> If I'm not missing something, "SELECT <targetlist>" without
> having FROM clause doesn't need to be tweaked. Thus
> insert_set_clause is useless and all we need here would be
> something like the following. (and the same for OVERRIDING.)
>
> + | SET set_clause_list from_clause
> + {
> + SelectStmt *n = makeNode(SelectStmt);
> + n->targetList = $2;
> + n->fromClause = $3;
> + $$ = makeNode(InsertStmt);
> + $$->selectStmt = (Node *)n;
> + $$->cols = $2;
> + }

While that would mostly work, it would prevent setting the column to its
default value using the DEFAULT keyword.

Only expressions specified in valuesLists allow DEFAULT to be used. Those
in targetList do not because transformInsertStmt() treats that as a general
SELECT statement and the grammar does not allow the use of DEFAULT there.

So this would generate a "DEFAULT is not allowed in this context" error
if only targetList was used:

INSERT INTO t set c1 = DEFAULT;

Regards,
Gareth

> regards.
>
> --
> Kyotaro Horiguchi
> NTT Open Source Software Center

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2019-07-19 02:46:27 Re: Documentation fix for adding a column with a default value
Previous Message David Rowley 2019-07-19 01:54:59 Re: Tid scan improvements