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 1ewuXX-0000Yz-MZ for pgsql-docs@arkaria.postgresql.org; Fri, 16 Mar 2018 18:57:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ewuXW-0000zX-DY for pgsql-docs@arkaria.postgresql.org; Fri, 16 Mar 2018 18:57:18 +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 1ewuXW-0000zO-25 for pgsql-docs@lists.postgresql.org; Fri, 16 Mar 2018 18:57:18 +0000 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ewuXS-0000sh-0S for pgsql-docs@lists.postgresql.org; Fri, 16 Mar 2018 18:57:17 +0000 Received: by mail-lf0-x22b.google.com with SMTP id x205-v6so16849943lfa.0 for ; Fri, 16 Mar 2018 11:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=timbira-com-br.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Y/BgGM8SwE3WeC6AsgFXrkqs8LmxUWcM1b/sMx/tqhs=; b=qptYOcrl5swHGxf9v1qgMm4utiZB7+z1d/FVQb010L8KPORuJssH5ylNFW0Qb4p3iy wbijkQ5PtgzQi80IRyD9AbytKMQxSy1u7yzdFB7rbvNlT5gfkdj5UXIcDjw6DWjBdbWh n09eTtZZHzjeLk8X4y+3BL1iqRx3/5hQhOjKUvfhi2+nqOB0hx+nDk+20diD5MVoqgoo gCaUo6Cpn/m1hdRTP1il9oxg2cwO522W++3H2a5Qtl9XITEYkIQ9Vm3U8usCqNLQE80J FDJWTbcfFi275tEvu4vZpKvi8ixCCBpDWUys11iIOvJ5PUHfPfNbgQTxeHVNk+FrVQk7 gTFw== 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=Y/BgGM8SwE3WeC6AsgFXrkqs8LmxUWcM1b/sMx/tqhs=; b=lRPe+2ZatTJeE0WqWTXm6WQuL9h/Ucfuqo9xK8bivxskjFu2X5uFYGr0T1pk2w4XFh jUAb8ypqMG+Piw9G2bPC4S9lUKTP1DJOQEDnqvcpeJF6s4ojGJb6CCrbkKW3LzNjUyui tahbi/+9EZB6SGNjAQViVQJoKGenjZny7gJYn9TAU0nC5/kqJibhxlROUNdUT0Ug/X4g IvoqQ4+T10vo6B/NdtSjBMyM+rEEBLpeL+gTUoV3PSoWUmBTlFq5yVClTM6tsDn5Q9kA KH5s6auy+SrpvxgLQ/Dzyc/f44uNKjXLMJ14Oad7SqnFyOFDosmCgV6SRJAFg7PCcbkv yh0Q== X-Gm-Message-State: AElRT7Ho/VczWLjCSazlr4jAq8v1UqDtnR7VaZb7sR+XePlOgU2LAKu9 luORWqOYURtyg+eYk9VSCRGts7hPST9xWhUklav7zg== X-Google-Smtp-Source: AG47ELv8MyKvu78AGnuqUE/CJ5BKEQWSaI7R1K36ujqOAHvBoJaDIAaPLYBIQr3WjYa4MLrGasgUwNAVaLvncFcq7ns= X-Received: by 2002:a19:2145:: with SMTP id h66-v6mr2073661lfh.63.1521226630396; Fri, 16 Mar 2018 11:57:10 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:570c:0:0:0:0:0 with HTTP; Fri, 16 Mar 2018 11:57:09 -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: Euler Taveira Date: Fri, 16 Mar 2018 15:57:09 -0300 Message-ID: Subject: Re: Synopsis of SELECT statement: UNION, INTERSECTION, EXCEPT To: Tom Lane Cc: dirk.lattermann@leanix.net, pgsql-docs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 2018-03-16 2:17 GMT-03:00 Tom Lane : > Euler Taveira writes: >> 2018-03-15 7:18 GMT-03:00 PG Doc comments form : >>> The SYNOPSIS section of the "SELECT" SQL command contains the line >>> [ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ] >>> (with a boldface "select"), but it is not clear what is meant by that >>> "select". > >> It is a bug in the synopsis. UNION et al cannot contain some elements >> (such as ORDER BY) that is allowed for a sub-select. The attached >> patch replace "select" with the correct element ("select_statement"). > > Well, "select_statement" isn't defined in the synopsis either. > We do define it implicitly in the UNION/INTERSECT/EXCEPT subsections, > but is that enough? > Is it worth inflate the synopsis with each element that appears in it? "join_type" and "window_definition" are not defined in the synopsis either. > I think the parenthetical remark in the "UNION Clause" section is a bit > shaky too: > > (ORDER BY and LIMIT can be attached to a subexpression if it is > enclosed in parentheses. Without parentheses, these clauses will be > taken to apply to the result of the UNION, not to its right-hand input > expression.) > Yup. It does not inform that the ORDER BY should be at the end of the UNION. > Also, whether or not that wording is right, it's not duplicated in the > INTERSECT or EXCEPT headings, where logically it ought to appear too. > We could duplicate it there maybe, but I'm starting to feel like this is > just doubling down on a bad documentation design. > I don't see it as a problem since that part will not (never | rarely) change. > The long and short of it is that UNION et al were wedged into the initial > synopsis in a way that's at best misleading and at worst a lie. But > I'm not sure how to make that better without also making it a lot more > confusing. A pedantically correct syntax synopsis would look something > like > The problem with adding "select_statement" to the synopsis is that it is not self-explainable... > 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. > ... I mean it is really difficult to present this part in a synopsis. I tend to agree that avoid defining some elements was a clever decision (because we have the opportunity to explain it in detail a few paragraphs below). Although, I don't see the "window_definition" in the synopsis I can explore its syntax a few lines above. IMO if users have a hard time finding the "select_statement" element, maybe we can add a link to each of those elements that have additional syntax and does not appear in the synopsis. > So, surely there's room for improvement here, but I'm not certain what > it'd look like. Maybe we should split out the discussion of set-operation > syntax altogether? How exactly? > It seems a radical change. I wouldn't certainly suggest unless chapter and/or section is a complete mess. I don't think it is the case. If a few more users also complain about the set-operators confusion, we should improve tutorial and add a few use-cases for it. -- Euler Taveira Timbira - http://www.timbira.com.br/ PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento