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 1jLuxx-0005gq-P9 for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2020 20:37:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jLuxw-0006aC-MX for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2020 20:37:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLuxw-0006WY-BG for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2020 20:37:00 +0000 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jLuxt-0007to-Sp for pgsql-hackers@postgresql.org; Tue, 07 Apr 2020 20:36:59 +0000 Received: by mail-qk1-x744.google.com with SMTP id g74so812011qke.13 for ; Tue, 07 Apr 2020 13:36:57 -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=0jCQUOdnwfCfPdCwqgaA5tErsSZrIkEWq3aF2GyIj40=; b=jXoJXzcLny9ztGjb0AT9+gpc1swKAXNMG8Fhx5jXdtxjjkksMVwHEPdl4dzdD+q0e3 9YGYLXoMIcDDBw2ZMaan3k1NdA6ZEAlvHumuyZCkCVW4w/sZSLZtT2tP10gpLwr0DYKq NwI/8Vy9H74+HOQBMzrL+HlvzvUFqHQ2JFqjgh4dGkM1+V9LX53HnHUVxFuERTpGCDzz os9SNJru/ugAvz4uxfWreFmh/JF7fA35p43vodC9LLmzm0EttZNQjWqA8mjMprNv+tn0 Aq6ZCrmJvZxd7QFVlsD5qfTpWvTiEjEauEeSFH5RON20yNHMWKbMIOWWiZ/oCagq6Xvf wzsw== 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=0jCQUOdnwfCfPdCwqgaA5tErsSZrIkEWq3aF2GyIj40=; b=qui9vZFizzXtfDV+IhHQilPU3I+lzV/qbOm7/VlTKOTn6tVFyHlX/CyViexsClo3YQ PlAY+h3UWLxWLfRiHbNzw3nnOj8dwytRJp4N0MxZkrbi/cuciSqrvaGb8dGMM6mXbCIM b0vVG9YUfdDOnaI19g879YCMfllZX/1NOtZfTEZtoRU0onIDCNjOZs6TFzcbOC3bVM62 g0vDyEHG96Nuz9KaarUyue4jQVSqjbfTNJLVdt8bsKX0GsV5WiggJ9R+coRu66tAvIXe 2XBBCYUsH6uEdBLMnIxaFJsm11oRm4aqXfp88NssX5wffL0RZ4GawbKIFthrq0HQIC20 rgew== X-Gm-Message-State: AGi0PuarEhIQOmtcaforsdP88uQ0sPSFxL/stUipo7QMYwPU5qMfKm8p VoG4zD18Kg5F0wtmFdRquxUbZA== X-Google-Smtp-Source: APiQypLxtukXYyu81Wz+Kmvt3QkwRkZL9zz1bjP8ZI2tIJRIJPY4LmeOO3Pt6/Ebn8lLa11SJiVVZA== X-Received: by 2002:a37:a090:: with SMTP id j138mr4241516qke.57.1586291817095; Tue, 07 Apr 2020 13:36:57 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id q11sm7439496qkq.109.2020.04.07.13.36.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 13:36:56 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 1657E300A5A; Tue, 7 Apr 2020 16:36:54 -0400 (-04) Date: Tue, 7 Apr 2020 16:36:54 -0400 From: Alvaro Herrera To: Surafel Temesgen Cc: Tomas Vondra , PostgreSQL Hackers , Andrew Gierth Subject: Re: FETCH FIRST clause WITH TIES option Message-ID: <20200407203654.GA15931@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200407004925.GA23627@alvherre.pgsql> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Pushed, with some additional changes. So *of course* when I add tests to verify that ruleutils, I find a case that does not work properly -- meaning, you get a view that pg_dump emits in a way that won't be accepted: CREATE VIEW limit_thousand_v_3 AS SELECT thousand FROM onek WHERE thousand < 995 ORDER BY thousand FETCH FIRST NULL ROWS WITH TIES; note the "NULL" there. ruleutils would gladly print this out as: View definition: SELECT onek.thousand FROM onek WHERE onek.thousand < 995 ORDER BY onek.thousand FETCH FIRST NULL::integer ROWS WITH TIES; which is then not accepted. The best fix I could come up for this was to reject a bare NULL in the limit clause. It's a very stupid fix, because you can still give it a NULL, using CREATE VIEW limit_thousand_v_3 AS SELECT thousand FROM onek WHERE thousand < 995 ORDER BY thousand FETCH FIRST (NULL+1) ROWS WITH TIES; and the like. But when ruleutils get this, it will add the parens, which will magically make it work. It turns out that the SQL standard is much more limited in what it will accept there. But our grammar (what we'll accept for the ancient LIMIT clause) is very lenient -- it'll take just any expression. I thought about reducing that to NumericOnly for FETCH FIRST .. WITH TIES, but then I have to pick: 1) gram.y fails to compile because of a reduce/reduce conflict, or 2) also restricting FETCH FIRST .. ONLY to NumericOnly. Neither of those seemed very palatable. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services