Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TDAj7-0001bQ-Sr for pgsql-bugs@postgresql.org; Sun, 16 Sep 2012 09:01:18 +0000 Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TDAj5-0007I4-8T for pgsql-bugs@postgresql.org; Sun, 16 Sep 2012 09:01:17 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TDAj4-0000N9-IE for pgsql-bugs@postgresql.org; Sun, 16 Sep 2012 09:01:14 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1TDAj3-0008JO-V0 for pgsql-bugs@postgresql.org; Sun, 16 Sep 2012 09:01:13 +0000 Date: Sun, 16 Sep 2012 09:01:13 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #7543: Invalid table alias: DELETE FROM table * To: pgsql-bugs@postgresql.org From: barrybrown@sierracollege.edu X-Pg-Spam-Score: -2.4 (--) X-Archive-Number: 201209/157 X-Sequence-Number: 34152 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 =3D 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 =3D 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?