Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0OCV-00B9yw-Cc for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Oct 2024 16:45:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t0OCR-00Etnj-NX for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Oct 2024 16:45:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0OCR-00Etna-D0 for pgsql-hackers@lists.postgresql.org; Mon, 14 Oct 2024 16:45:39 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0OCO-0012G6-KL for pgsql-hackers@lists.postgresql.org; Mon, 14 Oct 2024 16:45:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 49EGjRtf3748501; Mon, 14 Oct 2024 12:45:27 -0400 From: Tom Lane To: jian he cc: Pavel Stehule , Christoph Berg , Michael Banck , Tommy Pavlicek , =?UTF-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= , pgsql-hackers@lists.postgresql.org Subject: Re: Better error reporting from extension scripts (Was: Extend ALTER OPERATOR) In-reply-to: References: <560086.1698160614@sss.pgh.pa.us> <570833.1698162135@sss.pgh.pa.us> <66f33840.050a0220.1f9e60.7fb9@mx.google.com> <325394.1727365907@sss.pgh.pa.us> <571930.1727454668@sss.pgh.pa.us> <621972.1727459684@sss.pgh.pa.us> <1092841.1727552736@sss.pgh.pa.us> <2245576.1728418678@sss.pgh.pa.us> <3482022.1728839631@sss.pgh.pa.us> Comments: In-reply-to jian he message dated "Mon, 14 Oct 2024 11:38:47 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3748499.1728924327.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 14 Oct 2024 12:45:27 -0400 Message-ID: <3748500.1728924327@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk jian he writes: > On Mon, Oct 14, 2024 at 1:13 AM Tom Lane wrote: >> Right, but we might not have entered either of those previous >> if-blocks. > in src/backend/parser/gram.y > your makeRawStmt changes (v4) seem to guarantee that > RawStmt->stmt_location >= 0. Yes, I would expect that any RawStmt we see here will have valid stmt_location. What you seem to be missing is that an error could be thrown from > raw_parsetree_list = pg_parse_query(sql); before execute_sql_string reaches its loop over RawStmts. In that case we'll reach script_error_callback with callback_arg.stmt_location still being -1. > pg_parse_query(sql) doesn't use script_error_callback. Eh? We've put that on the error context callback stack. It is not pg_parse_query's decision whether it will be called. regards, tom lane