Hi,
I'm trying to understand a behavior where, with our Postgres client, a leading 
comment in a SQL script causes the CREATE FUNCTION statement following it to be 
not executed. I can't figure out if this is a bug somewhere or just a 
misunderstanding on 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 passes it to SQLAlchemy's execute(), I can 
see in the Postgres log that the leading comment is *not* stripped, and the 
function isn'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 comment but isn't, but that seems 
like a lot of responsibility to push onto a client application. I figured that 
would be the responsibility of the Postgres parser. 

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

Thanks
Philip



Reply via email to