Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exfqz-0006FU-OI for pgsql-docs@arkaria.postgresql.org; Sun, 18 Mar 2018 21:28:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1exfqy-0001Ru-Gp for pgsql-docs@arkaria.postgresql.org; Sun, 18 Mar 2018 21:28:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exfqy-0001Rj-8E for pgsql-docs@lists.postgresql.org; Sun, 18 Mar 2018 21:28:32 +0000 Received: from mail-qk0-x22d.google.com ([2607:f8b0:400d:c09::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1exfqu-0001A9-Vq for pgsql-docs@lists.postgresql.org; Sun, 18 Mar 2018 21:28:31 +0000 Received: by mail-qk0-x22d.google.com with SMTP id h187so3193490qkf.0 for ; Sun, 18 Mar 2018 14:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=NKkoVThSIKAwdOPVIn8SyxWVDuke2bXHN6W+23C+c2M=; b=bZLIZpwNQmPKO8it3PYzlz6BAUz6Z1Kz0GQhkFUxVm99ZKrtwuGqHEmPhNNNrZWuRe jxesmB/Ql/1J7vavvzip1xDtX5RrQQ07b/TE13Z0gp509f4pySglb2/V9vYUWXmXTnDw Zkb7OsF8EsT6eU/Fc5c0AYGxbpSrkftBdrUaiRZrQZtJ0f3iM2HF6OF8WlBFIbU1vhxM ZwTnJgLqMw7XGAbAEwv70oRV2cLX8VnRXgwrW0fhoOi51Eeap8fCS8Fv6cWIoCJjoi+I bF7LnbA4A8zYuXqCBH54KubbKjQwL4WYaDJ3BLp5JOu2ML/abb33OVtikovYr7BRefqF eLqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=NKkoVThSIKAwdOPVIn8SyxWVDuke2bXHN6W+23C+c2M=; b=mqWiHwDbQkRN3/vmr4vpcRJwXMO/ImV+cuFv2ht46oC0xDmZIflkQG4V6kT37j6avK bNHL5+ahMToaf7heip9MpS4DkfjizDokVw4c630KdEiTJL2IDnDjgyjMdAZFVqCmxtZL WC8Y2AHcCVzPeguOFmdSZLoogssT3qOCES3v9KlZMzKyPBikHzfvmgQqgczSrqkF7+Sx cPNloGcMi0lpqvyUgQwoGWRszHISb3zuFs+9lcbV5ygH0TloN/kTZAigQXkXOHdjxlwx TjR3BUX5gOar5HFo4waaKtGQXxcs01+Q0jz8jwW6g7kfyOM5cftoHF/5Fj4LZz9FsCM5 SYhg== X-Gm-Message-State: AElRT7F0ESh2h4714j0Ptn/PHFFQrcxXjdkNHwh0eihkTW1+9K2TckDY TppRrvp6EWhhEMKsvBHYMiOoC5fW9BHYkSRggZkC9Q== X-Google-Smtp-Source: AG47ELvL4zpjwcEaay4tu+dL7mFAFU80K0jxvJVKmtqSM6viP3roH884QOggsZUczo9Zt+vCGWTs+J8/jdeOZs96CCA= X-Received: by 10.55.21.40 with SMTP id f40mr13765942qkh.287.1521408506735; Sun, 18 Mar 2018 14:28:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.157.78 with HTTP; Sun, 18 Mar 2018 14:28:26 -0700 (PDT) In-Reply-To: <28115.1521177420@sss.pgh.pa.us> References: <152110913499.1223.7026776990975251345@wrigleys.postgresql.org> <28115.1521177420@sss.pgh.pa.us> From: "David G. Johnston" Date: Sun, 18 Mar 2018 14:28:26 -0700 Message-ID: Subject: Re: Synopsis of SELECT statement: UNION, INTERSECTION, EXCEPT To: Tom Lane Cc: Euler Taveira , dirk.lattermann@leanix.net, pgsql-docs@lists.postgresql.org Content-Type: multipart/alternative; boundary="001a1147d3ea9a31c60567b68587" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --001a1147d3ea9a31c60567b68587 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable As a first step we could do something like: =E2=80=8Bbasic_select_statement is: =E2=80=8B > SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] > [ * | expression [ [ AS ] output_name ] [, ...] ] > [ FROM from_item [, ...] ] > [ WHERE condition ] > [ GROUP BY grouping_element [, ...] ] > [ HAVING condition [, ...] ] > [ WINDOW window_name AS ( window_definition ) [, ...] ] > =E2=80=8Bfull_select_statement is basic_select_statement with the following possible additional clauses tacked onto the end: [ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | > LAST } ] [, ...] ] > [ LIMIT { count | ALL } ] > [ OFFSET start [ ROW | ROWS ] ] > [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ] > [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name > [, ...] ] [ NOWAIT | SKIP LOCKED ] [...] ] > > and that's still not right because ORDER BY et al can't be attached to a > select_stmt that's the argument of a set operation, so really we'd need > a couple of levels of nonterminals before we get down to the basic > "SELECT expression FROM ..." part. Nor has the use of parentheses been > mentioned yet. > =E2=80=8BThen we can define the set clauses in terms of basic_select_stmt a= nd parentheses-surrounded full_select_stmt. The result of the set clause is itself a type of basic_select_statement which can be made full by adding one or more of the additional clauses, including ORDER BY. David J. --001a1147d3ea9a31c60567b68587 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
As a first step we= could do something like:

=E2=80=8Bbasic_select_statement is:
=E2= =80=8B
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
=C2=A0 =C2=A0 [ * | expression [ [ AS ] output_name ] [, ...] ]
=C2=A0 =C2=A0 [ FROM from_item [, ...] ]
=C2=A0 =C2=A0 [ WHERE condition ]
=C2=A0 =C2=A0 [ GROUP BY grouping_element [, ...] ]
=C2=A0 =C2=A0 [ HAVING condition [, ...] ]
=C2=A0 =C2=A0 [ WINDOW window_name AS ( window_definition ) [, ...] ]

=E2=80=8Bfull_select_statement is basic_s= elect_statement with the following possible additional clauses tacked onto = the end:

=C2=A0 =C2=A0 [ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS= { FIRST | LAST } ] [, ...] ]
=C2=A0 =C2=A0 [ LIMIT { count | ALL } ]
=C2=A0 =C2=A0 [ OFFSET start [ ROW | ROWS ] ]
=C2=A0 =C2=A0 [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]
=C2=A0 =C2=A0 [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF tab= le_name [, ...] ] [ NOWAIT | SKIP LOCKED ] [...] ]

and that's still not right because ORDER BY et al can't be attached= to a
select_stmt that's the argument of a set operation, so really we'd = need
a couple of levels of nonterminals before we get down to the basic
"SELECT expression FROM ..." part.=C2=A0 Nor has the use of paren= theses been
mentioned yet.

=E2=80=8BThen we can defin= e the set clauses in terms of basic_select_stmt and parentheses-surrounded = full_select_stmt. The result of the set clause is itself a type of basic_se= lect_statement which can be made full by adding one or more of the addition= al clauses, including ORDER BY.

David J.

<= /div>


--001a1147d3ea9a31c60567b68587--