Re: [PATCH] Implement INSERT SET syntax - Mailing list pgsql-hackers

From Gareth Palmer
Subject Re: [PATCH] Implement INSERT SET syntax
Date
Msg-id 823D82DF-70B9-4662-BBEA-ECEB72EF725D@internetnz.net.nz
Whole thread Raw
In response to Re: [PATCH] Implement INSERT SET syntax  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
Responses Re: [PATCH] Implement INSERT SET syntax  (Ibrar Ahmed <ibrar.ahmad@gmail.com>)
List pgsql-hackers
Hi Kyotaro,

Thank-you for looking at the patch.

> On 18/07/2019, at 6:54 PM, Kyotaro Horiguchi <horikyota.ntt@gmail.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




pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: Tid scan improvements
Next
From: Michael Paquier
Date:
Subject: Re: Documentation fix for adding a column with a default value