pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: barrybrown@sierracollege.edu
To: pgsql-bugs@postgresql.org
Subject: BUG #7543: Invalid table alias: DELETE FROM table *
Date: Sun, 16 Sep 2012 09:01:13 +0000
Message-ID: <E1TDAj3-0008JO-V0@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      7543
Logged by:          Barry Brown
Email address:      barrybrown@sierracollege.edu
PostgreSQL version: 9.1.5
Operating system:   Ubuntu 12.04
Description:        

I sometime see my users delete all rows from a table using a command like
this:

DELETE FROM customer *;

The question is: what is the star? Is it a table alias or an
output_expression?

The grammar for DELETE is:

[ WITH [ RECURSIVE ] with_query [, ...] ]
DELETE FROM [ ONLY ] table [ [ AS ] alias ]
    [ USING using_list ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

According to the grammar, the star could be an alias. We can alias the table
being affected with a "normal" alias. The following also works:

DELETE FROM customer foo;
DELETE FROM customer foo where foo.id = 1;

However, the star isn't treated as an alias in this next command. Instead,
it generates a syntax error, as one might expected:

DELETE FROM customer * where *.id = 1;

So perhaps the star is an output_expression. The grammar for the RETURNING
clause is:

RETURNING * | output_expression [ [ AS ] output_name ] [, ...]

Since it has no parentheses to alter the operator precedence, it is
interpreted as:

(RETURNING *) | (output_expression [ [ AS ] output_name ] [, ...])

In other words, one can write just an output_expression without the
RETURNING keyword. However, I'm sure the grammar is supposed to require the
RETURNING keyword. Consequently, the grammar ought to be:

RETURNING (* | output_expression [ [ AS ] output_name ] [, ...])

The written documentation implies that * is a valid output_expression.

In summary:
Should * be an acceptable table alias for the DELETE command?
Should the grammar for the RETURNING clause include some parentheses to make
it clearer what's expected?





view thread (4+ messages)  latest in thread

Message-ID: <E1TDAj3-0008JO-V0@wrigleys.postgresql.org>
Permalink:  ../E1TDAj3-0008JO-V0@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1TDAj3-0008JO-V0@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: barrybrown@sierracollege.edu
  Subject: Re: BUG #7543: Invalid table alias: DELETE FROM table *
  In-Reply-To: <E1TDAj3-0008JO-V0@wrigleys.postgresql.org>
  References: <E1TDAj3-0008JO-V0@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox