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 1qZGh0-004nC7-Av for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Aug 2023 20:12:34 +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 1qZGgy-00CfJt-Nu for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Aug 2023 20:12:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qZGgy-00CfJa-Eg for pgsql-bugs@lists.postgresql.org; Thu, 24 Aug 2023 20:12:32 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qZGgv-000lhG-GE for pgsql-bugs@lists.postgresql.org; Thu, 24 Aug 2023 20:12:30 +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 37OKCQTF3972354; Thu, 24 Aug 2023 16:12:26 -0400 From: Tom Lane To: Jonathan Zacharuk cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: Error when using unquoted identifier that contains the word end in a begin atomic block In-reply-to: References: Comments: In-reply-to Jonathan Zacharuk message dated "Thu, 24 Aug 2023 19:53:03 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3972352.1692907946.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 24 Aug 2023 16:12:26 -0400 Message-ID: <3972353.1692907946@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jonathan Zacharuk writes: > It seems to me that within a BEGIN ATOMIC block the use of the word "end= " within an unquoted identifier is causing an error. I think your problem is somewhere on the client side. > -- This function is successfully created (note the quoted "effective_end= _date"). > CREATE OR REPLACE FUNCTION test_function_success() RETURNS TIMESTAMP > LANGUAGE SQL > BEGIN ATOMIC > SELECT DISTINCT "effective_end_date" > FROM test_view; > END For me, this works (in psql) with or without the double quotes: regression=3D# CREATE OR REPLACE FUNCTION test_function_success() RETURNS = TIMESTAMP LANGUAGE SQL BEGIN ATOMIC SELECT DISTINCT "effective_end_date" FROM test_view; END; CREATE FUNCTION regression=3D# CREATE OR REPLACE FUNCTION test_function_success() RETURNS = TIMESTAMP LANGUAGE SQL BEGIN ATOMIC SELECT DISTINCT effective_end_date FROM test_view; END; CREATE FUNCTION > -- This function fails to be created. I would expect this to work. > CREATE OR REPLACE FUNCTION test_function_fail() RETURNS TIMESTAMP > LANGUAGE SQL > BEGIN ATOMIC > SELECT DISTINCT effective_end_date > FROM test_view > ERROR: syntax error at end of input > LINE 6: FROM test_view > ^ I can't help noticing that the trailing END is missing from what you show here, and it seems pretty clear that the syntax error is about that, not about the effective_end_date identifier. So the real question is why the CREATE FUNCTION command is getting sent to the server before it's complete. If this isn't flat-out pilot error, then I guess whatever client you are using (apparently not psql) is getting confused about which occurrence of "end" terminates the command. You should take this up with the authors of said client software. regards, tom lane