Re: Why forbid "INSERT INTO t () VALUES ();" - Mailing list pgsql-hackers

From Isaac Morland
Subject Re: Why forbid "INSERT INTO t () VALUES ();"
Date
Msg-id CAMsGm5e9RmakEn0zDKKAQ5=oDT42v+jh6Qki6ToX+9hTQ9GSFg@mail.gmail.com
Whole thread Raw
In response to Why forbid "INSERT INTO t () VALUES ();"  (Fabien COELHO <coelho@cri.ensmp.fr>)
Responses Re: Why forbid "INSERT INTO t () VALUES ();"  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
On Wed, 24 Jun 2020 at 08:18, Fabien COELHO <coelho@cri.ensmp.fr> wrote:
I would like to create an "all defaults" row, i.e. a row composed of the 
default values for all attributes, so I wrote:

   INSERT INTO t() VALUES ();

This is forbidden by postgres, and also sqlite.

This is not the only area where empty tuples are not supported. Consider:

PRIMARY KEY ()

This should mean the table may only contain a single row, but is not supported.

Also, GROUP BY supports grouping by no columns, but not in a systematic way: Using aggregate functions with no explicit GROUP BY clause will result in grouping by no columns (i.e., entire result set is one group); I also found that I could GROUP BY NULL::integer, abusing the column number syntax. But things like GROUP BY ROLLUP () are not supported.

On the plus side, empty rows are supported, although the explicit ROW keyword is required.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Open Item: Should non-text EXPLAIN always show properties?
Next
From: Andres Freund
Date:
Subject: Re: Keep elog(ERROR) and ereport(ERROR) calls in the cold path