Re: Proposal: INSERT ... BY NAME

From: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
To: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Re: Proposal: INSERT ... BY NAME
Date: 2026-07-22 11:39:33
Message-ID: CAJTYsWXg6S6RaYcTXgcdtk+j58MM23rQVK_SSQ7tsgkJYJJj+g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Fri, 10 Jul 2026 at 20:15, Marcos Pegoraro <marcos(at)f10(dot)com(dot)br> wrote:

> Em sex., 3 de jul. de 2026 às 08:08, Ayush Tiwari <
> ayushtiwari(dot)slg01(at)gmail(dot)com> escreveu:
>
>> - BY NAME requires a query source and is rejected for VALUES and DEFAULT
>> VALUES. BY POSITION is accepted with DEFAULT VALUES as a no-op.
>>
> Is it rejected for VALUES, even if those VALUES are named ?
> This one should work, doesn't it ?
> insert into t1 (c1, c2) by name select * from (Values (1,2)) x(c2, c1)
>

Yes, it works, the source there is a SELECT, not a bare VALUES list,
so the aliased columns c2/c1 give BY NAME real names to match on:

insert into t1 (c1, c2) by name select * from (Values (1,2)) x(c2, c1);
-- c1=2, c2=1

Only the *bare* VALUES form is rejected, since a VALUES row has no column
names of its own. Maybe I'll reword the docs to make that distinction
clear.

And is missing a test for select *, right ?
> create table a(a int, b int, c int);
> create table b(b int, c int, a int);
> insert into a by name select * from b;
>

Good catch, that path isn't tested. It works (the star expands to b's
column names before matching), so I'll add a regression test for it.

Thanks for the review!

Regards,
Ayush

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayush Tiwari 2026-07-22 11:44:53 Re: Proposal: INSERT ... BY NAME
Previous Message Christoph Berg 2026-07-22 11:30:19 Re: Available disk space per tablespace