Re: Trailing comma support in SELECT statements

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Trailing comma support in SELECT statements
Date: 2014-10-03 21:02:44
Message-ID: 1412370164737-5821694.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Dunstan wrote
> On 10/03/2014 12:20 PM, Bruce Momjian wrote:
>> On Sun, Sep 28, 2014 at 01:42:46PM +0200, Bogdan Pilch wrote:
>>> Hi,
>>> I have created a small patch to postgres source (in particular the
>>> psql part of it) that accepts trailing comma at the end of list in
>>> SELECT statement.
>>>
>>> The idea is to be able to say both (with the same result):
>>> SELECT a, b, c from t;
>>> SELECT a, b, c, from t;
>>>
>>> Attached you can find a patch containing regression test (incorporated
>>> into the serial_schedule).
>>> My patch is relative to origin/REL9_4_STABLE branch as that is the one
>>> I started from.
>>>
>>> My plea is to have this change merged into the main stream so that it
>>> becomes available in upcoming releases.
>>>
>>> This modification does not require any interaction with user.
>>> It does not create any backward compatibility issues.
>> Interesting --- I know some languages allow trailing delimiters, like
>> Perl and Javascript. Could this mask query errors? Does any other
>> database accept this? Seems this would need to be done in many other
>> places, like UPDATE, but let's first decide if we want this.
>>
>> FYI, it is usually better to discuss a feature before showing a patch.
>>
>
> Javascript might accept it, but it's not valid JSON.
>
> The case for doing it is that then you can easily comment out any entry
> at all in a select list:
>
> select
> foo as f1,
> bar as f2,
> -- baz as f3,
> from blurfl

Should we also allow:

SELECT
, col1
, col2
, col3
FROM ...

?

The other reason for this would be to build dynamic SQL more easily via a
loop.

Barring arguments showing danger allowing I don't see a reason to reject
this; let people decide whether they want to utilize it on stylistic or
compatibility grounds.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Trailing-comma-support-in-SELECT-statements-tp5821613p5821694.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-10-03 21:12:25 Re: [RFC] Incremental backup v2: add backup profile to base backup
Previous Message Peter Geoghegan 2014-10-03 21:01:18 Re: UPSERT wiki page, and SQL MERGE syntax