Subject: Re: Allowing additional commas between columns, and at the end of the SELECT clause

From: Dagfinn Ilmari Mannsåker <[email-masked]>
Date: Mon, 13 May 2024 13:28:19 +0100

Matthias van de Meent <[email-masked]> writes:

> On Mon, 13 May 2024 at 10:42, Artur Formella <[email-masked]> wrote:
>> Motivation:
>> Commas of this type are allowed in many programming languages, in some
>> it is even recommended to use them at the ends of lists or objects.
>
> Single trailing commas are a feature that's more and more common in
> languages, yes, but arbitrary excess commas is new to me. Could you
> provide some examples of popular languages which have that, as I can't
> think of any.

The only one I can think of is Perl, which I'm not sure counts as
popular any more.  JavaScript allows consecutive commas in array
literals, but they're not no-ops, they create empty array slots:

    ❯ js
    Welcome to Node.js v18.19.0.
    Type ".help" for more information.
    > [1,,2,,]
    [ 1, <1 empty item>, 2, <1 empty item> ]

- ilmari

---

From: Tom Lane <[email-masked]>
Date: Mon, 13 May 2024 10:11:34 -0400

> literals, but they're not no-ops, they create empty array slots:

I'm fairly down on this idea for SQL, because I think it creates
ambiguity for the ROW() constructor syntax.  That is:

	(x,y) is understood to be shorthand for ROW(x,y)

	(x) is not ROW(x), it's just x

	(x,) means what?

I realize the original proposal intended to restrict the legality of
excess commas to only a couple of places, but to me that just flags
it as a kluge.  ROW(...) ought to work pretty much the same as a
SELECT list.

As already mentioned, if you can get some variant of this through the
SQL standards process, we'll probably adopt it.  But I doubt that we
want to get out front of the committee in this area.

			regards, tom lane

---

From: Dagfinn Ilmari Mannsåker <[email-masked]>
Date: Mon, 13 May 2024 17:35:42 +0100

> 	(x) is not ROW(x), it's just x

Python has a similar issue: (x, y) is a tuple, but (x) is just x, and
they use the trailing comma to disambiguate, so (x,) creates a
single-item tuple.  AFAIK it's the only place where the trailing comma
is significant.

> it as a kluge.  ROW(...) ought to work pretty much the same as a

Yeah, a more principled approach would be to not special-case target
lists, but to allow one (and only one) trailing comma everywhere:
select, order by, group by, array constructors, row constructors,
everything that looks like a function call, etc.

> want to get out front of the committee in this area.

Agreed.

- ilmari

---

From: Tom Lane <[email-masked]>
Date: Mon, 13 May 2024 13:14:35 -0400

> single-item tuple.  AFAIK it's the only place where the trailing comma

Ugh :-(.  The semantic principle I'd prefer to have here is "a trailing
comma is ignored", but what they did breaks that.  But then again,
I'm not particularly a fan of anything about Python's syntax.

> everything that looks like a function call, etc.

If it can be made to work everywhere, that would get my vote.
I'm not sure if any other ambiguities arise, though.  SQL has
a lot of weird syntax corners (and the committee keeps adding
more :-().

			regards, tom lane