Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jajAu-0004kr-S8 for pgsql-hackers@arkaria.postgresql.org; Mon, 18 May 2020 17:03:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jajAt-0003OW-Pb for pgsql-hackers@arkaria.postgresql.org; Mon, 18 May 2020 17:03:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jajAt-0003OP-Fe for pgsql-hackers@lists.postgresql.org; Mon, 18 May 2020 17:03:35 +0000 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jajAo-00006k-05 for pgsql-hackers@lists.postgresql.org; Mon, 18 May 2020 17:03:32 +0000 Received: by mail-qk1-x732.google.com with SMTP id n14so10828634qke.8 for ; Mon, 18 May 2020 10:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=Im8V+0sgtXK1sNziPWnCuXrkSDuUVlkFGrnSQSXw6Ik=; b=1O1kYfGqMGOr5dWsHxyRV+cY3zOj8odX2HXihykdWhuZ9tgxw/Csi1resnQyt9hsbo GSytBG4moT+bd3ZcpU2oByH+GnJakYtz02HzMrdu1c3+lJ4ESekHQ5BOgsmpuT2GWPFL jstj1FQV3lbXnoOoEzKuQciovvjFY4Z+nAljA7tStdpY48sBQ8XxgWBVK0wtR9xLxSdK ZahR1YsJo8C225pyhsya/d1whnvpCLg55EOMOOBbAhJdVs5EDUjWzNOQksQmpodjsioV JWqBveq8VAeykfEnJGgMjbmowdNYEx9hNwNS9YRjHcJUUYC9yHX+XRlwNDiEpJOTYanB TJPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Im8V+0sgtXK1sNziPWnCuXrkSDuUVlkFGrnSQSXw6Ik=; b=dZjxBXDsZqbilh6C9PG0SPtPvAS4ihNbLEejCYlsSVTK2D+KQGsAnBWcVgKmeAjgCO +s032ty5Cv1YQshlH5868wA75XvJx5TA8vUBbJtSY7i8Ggo3Mr6R8LDrO4aUnAvHin6w Ck7Yh4RVJreA2XAom19O8pk2qt8QNTI56+jpMwBUNUPhcgTsmFkbOuQONp+1y8YkbkGn BpMBIt13wGo4KhSn9pgw1EOVxdlk7dz8ICEvrncOP0VpzjbmcnER6ajs9kxLnX0wrZz6 YZsrJjZmvq2/lWFpLVkwOQ6J9pahOFmEoZkqEpCLvUXxMNQsWnicYKsAAEnaAwmKHJBd Ly6Q== X-Gm-Message-State: AOAM533Gn7dVsn2kBDi8oVCqjuTlfQm9or+bGeWLWMM2FJmFYa5uH/cx +nw4OBHdtj4z8C/DYikp4MFUzEynj6BGo00LUp3UaTQ32SM7KjJt3s/ryQ1Jrt8GqwlYCRuLGMr b1+vX7T6obXFgYZwhvj7RpBSfRYiziersYQ44HsBECHn4LOyIfQi4QPJvNDJlcM5pkwLSbssj3r KyX99BYVHci6LJHT6s X-Google-Smtp-Source: ABdhPJxeLxCjW3x/iI4V5wUes4vtB0fouubY7one+c+iVs2D+SmEikQ0kXS5igVokeE3PY+Yzz+3Zg== X-Received: by 2002:a37:a603:: with SMTP id p3mr16044054qke.133.1589821406591; Mon, 18 May 2020 10:03:26 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id 9sm1089029qko.29.2020.05.18.10.03.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 10:03:25 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 3515930076A; Mon, 18 May 2020 13:03:23 -0400 (-04) Date: Mon, 18 May 2020 13:03:23 -0400 From: Alvaro Herrera To: Vik Fearing Cc: PostgreSQL Hackers Subject: Re: Missing grammar production for WITH TIES Message-ID: <20200518170323.GA14610@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="opJtzjQTFsWo+cga" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6aa690ef-551d-e24f-2690-c38c2442947c@postgresfriends.org> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --opJtzjQTFsWo+cga Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2020-May-18, Vik Fearing wrote: > The syntax for FETCH FIRST allows the to be > absent (implying 1). > > We implement this correctly for ONLY, but WITH TIES didn't get the memo. Oops, yes. I added a test. Will get this pushed immediately after I see beta1 produced. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --opJtzjQTFsWo+cga Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-WITH-TIES-number-of-rows-is-optional-and-default-to-.patch" From bdd724370215a550586e49a2f8ce2f554bdf79f4 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 18 May 2020 11:57:05 -0400 Subject: [PATCH] WITH TIES: number of rows is optional and default to one Author: Vik Fearing --- src/backend/parser/gram.y | 8 ++++++++ src/test/regress/expected/limit.out | 17 +++++++++++++++++ src/test/regress/sql/limit.sql | 5 +++++ 3 files changed, 30 insertions(+) diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 3c78f2d1b5..a24b30f06f 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11816,6 +11816,14 @@ limit_clause: n->limitOption = LIMIT_OPTION_COUNT; $$ = n; } + | FETCH first_or_next row_or_rows WITH TIES + { + SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit)); + n->limitOffset = NULL; + n->limitCount = makeIntConst(1, -1); + n->limitOption = LIMIT_OPTION_WITH_TIES; + $$ = n; + } ; offset_clause: diff --git a/src/test/regress/expected/limit.out b/src/test/regress/expected/limit.out index a4e175855c..e6f6809fbe 100644 --- a/src/test/regress/expected/limit.out +++ b/src/test/regress/expected/limit.out @@ -576,6 +576,23 @@ SELECT thousand 0 (10 rows) +SELECT thousand + FROM onek WHERE thousand < 5 + ORDER BY thousand FETCH FIRST ROWS WITH TIES; + thousand +---------- + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +(10 rows) + SELECT thousand FROM onek WHERE thousand < 5 ORDER BY thousand FETCH FIRST 1 ROW WITH TIES; diff --git a/src/test/regress/sql/limit.sql b/src/test/regress/sql/limit.sql index afce5019b2..d2d4ef132d 100644 --- a/src/test/regress/sql/limit.sql +++ b/src/test/regress/sql/limit.sql @@ -161,6 +161,10 @@ SELECT thousand FROM onek WHERE thousand < 5 ORDER BY thousand FETCH FIRST 2 ROW WITH TIES; +SELECT thousand + FROM onek WHERE thousand < 5 + ORDER BY thousand FETCH FIRST ROWS WITH TIES; + SELECT thousand FROM onek WHERE thousand < 5 ORDER BY thousand FETCH FIRST 1 ROW WITH TIES; @@ -168,6 +172,7 @@ SELECT thousand SELECT thousand FROM onek WHERE thousand < 5 ORDER BY thousand FETCH FIRST 2 ROW ONLY; + -- should fail SELECT ''::text AS two, unique1, unique2, stringu1 FROM onek WHERE unique1 > 50 -- 2.20.1 --opJtzjQTFsWo+cga--