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 1lVJpU-0006yJ-1g for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Apr 2021 20:03:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lVJpR-0007cz-51 for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Apr 2021 20:03:37 +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 1lVJpQ-0007cp-UH for pgsql-hackers@lists.postgresql.org; Sat, 10 Apr 2021 20:03:36 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lVJpM-0006zO-28 for pgsql-hackers@lists.postgresql.org; Sat, 10 Apr 2021 20:03:36 +0000 Received: by mail-pl1-x633.google.com with SMTP id y2so4342016plg.5 for ; Sat, 10 Apr 2021 13:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/Zlf7IMvFxFeH9ioVELM0e0mcyEKau+lbumnq2p//x8=; b=Gdvh26i/Y33WxRfiwtrbHR3HgtEE3mgnMYW+R45y5OY9EQXb94NjnqtC1MoAjQVyG2 AwoWwLXl+g4oJXHqFELocyv++ZM7x8uMfprWcZLpH4+ljCVNo0gn9zkRMvy2Zdx6cvo7 Wz7F6TAUoBXCN9zdfk6XqyDqJvMf7iWnI3C+I= 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/Zlf7IMvFxFeH9ioVELM0e0mcyEKau+lbumnq2p//x8=; b=GI8iaznRuA8sn8bjN4sI2XpxLuKXawD7AYiGgE/vr/FEaj2Ww66yT3uZ4Kye+Yk0SS UwythoZcv/X3o8xrPdCH2jLdN4mU7sY+k+hSqewbfjfzIDKf2nitWQQ7hy5PF/JJcriC 4cVK3srYL0H7PfQ0MaxXvrNZSLPsEzvdw8FMBjdVjgrO/9RX9MgEFrLXGP90WSE1pqzI tV9Ujg2nwkyhT/x610pzjZpCjInm9VmH172sxwpBF6+C3lGrCP+I8R9wLXssJbKKa9Ea CCPRjAvmUonS1yaMcI41TVO71ARLeNxwfD9EamQXXtGK8NljhkQi+JZ+aL7VXUsu1J3t ymnA== X-Gm-Message-State: AOAM5310W2+P6v/qbKUEsOxg1uY2ssgr1pR0dXrj2F7JXpi3S5g9NxB9 bOx0O+FjVSkMsNC1qVkrVoerBw== X-Google-Smtp-Source: ABdhPJyAH8Vux9eGKD8IDlXZLVC38zeoChWYEyN/gc+1bjJVFXGxoGDgPQ9KVEKRzkofG4O5jd8nkQ== X-Received: by 2002:a17:903:310f:b029:ea:c9ad:4fb2 with SMTP id w15-20020a170903310fb02900eac9ad4fb2mr3080809plc.12.1618085009673; Sat, 10 Apr 2021 13:03:29 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::46]) by smtp.gmail.com with ESMTPSA id 195sm6166963pge.7.2021.04.10.13.03.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Apr 2021 13:03:29 -0700 (PDT) Date: Sat, 10 Apr 2021 13:03:26 -0700 From: Noah Misch To: Tom Lane Cc: Julien Rouhaud , Michael Paquier , Andres Freund , Peter Eisentraut , Jaime Casanova , PostgreSQL Hackers Subject: Re: SQL-standard function body Message-ID: <20210410200326.GD978274@rfd.leadboat.com> References: <1819824.1617858962@sss.pgh.pa.us> <20210408052759.7bmyawm4djnrux6y@alap3.anarazel.de> <1820954.1617860500@sss.pgh.pa.us> <20210408063514.houn2s3yxcorukdf@alap3.anarazel.de> <20210408111121.lsh6cvwjgk6ku7m5@nol> <2197698.1617984583@sss.pgh.pa.us> <20210410033014.GA993491@rfd.leadboat.com> <2298215.1618066335@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2298215.1618066335@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Apr 10, 2021 at 10:52:15AM -0400, Tom Lane wrote: > Noah Misch writes: > > On Fri, Apr 09, 2021 at 12:09:43PM -0400, Tom Lane wrote: > >> The real value of 0003 of course would be to get an error cursor at > >> runtime > > > A key benefit of $SUBJECT is the function body following DDL renames: > > Agreed. But ... > > > After the rename, any stored prosrc is obsolete. To show accurate error > > cursors, deparse prosqlbody and use that in place of prosrc. > > ... I'm not sure this conclusion follows. There are two problems with it: > > 1. I don't see an acceptably low-overhead way to mechanize it. > Deparsing prosqlbody is unlikely to be safe in a post-error transaction, > but surely we'd not want to expend that cost in advance on every use > of a SQL function. Even ignoring that, the act of deparsing would not > in itself tell you what offset to use. Should we deparse and then > re-parse to get a new node tree with corrected token locations? If you really want those error cursors, yes. (I feel we can continue to live without them; their absence is no more important than it was ten years ago.) One can envision several ways to cache that high-overhead work. Otherwise, the usual PostgreSQL answer would be to omit an error cursor, not show one that reflects an obsolete sense of the function. If the original CREATE FUNCTION query text were so valuable, I'd be arguing to preserve it across dump/reload. > 2. The reason we can get away with showing a fragment of a large query > (or function body) in an error message is that the user is supposed to > be able to correlate the display with what she wrote. That assumption > falls to the ground if the display is based on a deconstruction that is > virtually certain to have line breaks in different places, not to mention > that the details of what is shown may be substantially different from the > original. Preferences on this matter will be situation-dependent. If I do CREATE FUNCTION f() ...; SELECT f() all in one sitting, then it's fine for an error in the SELECT to show the function I wrote. If I'm calling a function defined years ago, I'm likely to compare the error report to "\sf foo" and not likely to compare it to a years-old record of the SQL statement. I think it's fine to expect users to consult "\sf foo" when the user is in doubt. > Still, I take your point that the original text may be less useful > for this purpose than I was supposing.