Leading comments and client applications - Mailing list pgsql-general

From Philip Semanchuk
Subject Leading comments and client applications
Date
Msg-id 265623A4-F304-4E68-90D0-343F614DB2B7@americanefficient.com
Whole thread Raw
Responses Re: Leading comments and client applications
Re: Leading comments and client applications
Re: Leading comments and client applications
List pgsql-general
Hi,
I'm trying to understand a behavior where, with our Postgres client, a leading comment in a SQL script causes the
CREATEFUNCTION statement following it to be not executed. I can't figure out if this is a bug somewhere or just a
misunderstandingon my part. I would appreciate some help understanding. 

Here's the contents of foo.sql --

-- this is a comment
CREATE FUNCTION foo(bar text) RETURNS text AS $$
    SELECT bar
$$
LANGUAGE sql IMMUTABLE PARALLEL SAFE
;


When I feed that to 'psql -f foo.sql', the function is created as I expect. In the Postgres log, the leading comment
*doesn't*appear. I see the same behavior if I just copy/paste the function into psql. 

Our test system uses Python 3.8, SQLAlchemy 1.3.6, and psycopg 2.8.5, and when our test harness reads foo.sql and
passesit to SQLAlchemy's execute(), I can see in the Postgres log that the leading comment is *not* stripped, and the
functionisn't created. 

The server is Postgres 11.

My naive interpretation is that one of the client layers (SQLAlchemy or psycopg2) should be stripping the leading
commentbut isn't, but that seems like a lot of responsibility to push onto a client application. I figured that would
bethe responsibility of the Postgres parser.  

I'd be grateful for any insights about what I'm missing.

Thanks
Philip




pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Get primary key of a table through SPI
Next
From: "David G. Johnston"
Date:
Subject: Re: Leading comments and client applications