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 1nXnsv-0008Rr-Gy for pgsql-general@arkaria.postgresql.org; Fri, 25 Mar 2022 17:38:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nXnsu-000488-99 for pgsql-general@arkaria.postgresql.org; Fri, 25 Mar 2022 17:38:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nXnst-00047z-Qi for pgsql-general@lists.postgresql.org; Fri, 25 Mar 2022 17:37:59 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nXnsn-00033i-Hr for pgsql-general@lists.postgresql.org; Fri, 25 Mar 2022 17:37:58 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id C184167C0; Fri, 25 Mar 2022 18:37:49 +0100 (CET) Date: Fri, 25 Mar 2022 18:37:49 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Leading comments and client applications Message-ID: <20220325173749.soe6onlheymwt4y6@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <265623A4-F304-4E68-90D0-343F614DB2B7@americanefficient.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="4nx2de2bw7sbskt7" Content-Disposition: inline In-Reply-To: <265623A4-F304-4E68-90D0-343F614DB2B7@americanefficient.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --4nx2de2bw7sbskt7 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2022-03-25 11:32:24 -0400, Philip Semanchuk wrote: > 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. >=20 > Here's the contents of foo.sql -- >=20 > -- this is a comment > CREATE FUNCTION foo(bar text) RETURNS text AS $$ > SELECT bar > $$ > LANGUAGE sql IMMUTABLE PARALLEL SAFE > ; >=20 >=20 > 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. >=20 > 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. I cannot reproduce this with plain psycopg: % cat foo #!/usr/bin/python3 import psycopg2 db =3D psycopg2.connect("") csr =3D db.cursor() csr.execute( """ -- this is a comment CREATE FUNCTION foo(bar text) RETURNS text AS $$ SELECT bar $$ LANGUAGE sql IMMUTABLE PARALLEL SAFE """) db.commit() % ./foo % psql psql (13.6 (Ubuntu 13.6-1.pgdg20.04+1), server 11.15 (Ubuntu 11.15-1.pgdg20= =2E04+1)) Type "help" for help. hjp=3D> \df foo List of functions =E2=95=94=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=A4=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =A4=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=A4=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A4=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=97 =E2=95=91 Schema =E2=94=82 Name =E2=94=82 Result data type =E2=94=82 Argume= nt data types =E2=94=82 Type =E2=95=91 =E2=95=9F=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=95=A2 =E2=95=91 public =E2=94=82 foo =E2=94=82 text =E2=94=82 bar te= xt =E2=94=82 func =E2=95=91 =E2=95=9A=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=A7=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =A7=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=A7=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A7=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=9D (1 row) hjp=3D> select foo('x*'); =E2=95=94=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=97 =E2=95=91 foo =E2=95=91 =E2=95=9F=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=95=A2 =E2=95=91 x* =E2=95=91 =E2=95=9A=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=9D (1 row) Time: 1.296 ms hjp=3D> \q So like others I suspect that SQLAlchemy is doing something weird here. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --4nx2de2bw7sbskt7 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmI9/egACgkQ8g5IURL+ KF1KNg//R2UV2HSNgKcDEh03ZQiktIqfxWQhUWlZb+IrSlZAiHbLKp1Y+e1icCc/ EE0d3i5KwNTNvnyJu83TqDmeFhmpkoEhbxytlQ90L0AlB1YPP8at44cKaxQIfARa kSv8FyHGlgpEI26G+p12fsFYau046InP8f5BVqUNIlnUghUgQ/Q2I0kk0y3PolMQ cA8GEE4LSfOiTa/8Axmjpegtr0mua7Z0VnMGxz8pAVQty5iHOnqa9iB755aC/a5m WGUj+YrWDtaLuE7HZs3x1Mj+CPurBcfB/ZQ2pObNqnKzN7/970yFZ1qWAGZSNIQW 3oiQhNx0s6hq7X+02UL7ZPPxKE+qrhymu/vR2F5yHCHL5LIHXZ68XCL4RVrm8ujR gvxZsN68Oy06wlpsYTAoxU+YeKLAm8Z219/atuPY9XpQqB2odlUSTh/DoyvRkTU/ VSHF1yp2HqtUWo5XvSLsRxdNLBz+4y4HVwC0Yfz7jv9lTW3ETrwbCeHu/sDWKEWu ykjoc7r96myrG+R5wvz9gtwMPvx1A+G41aFuVEQaZ++HpEZhLZbJystVXAveilaR Vrb+soj4ZooapEdebhZeByXJM5DErgVNNpsyta58gDYjiTx0ZShLbJiYEFYs0uGA ruahnkIMoEI4m0pNft9lWpwBy5kfACGGjh7OUCc6DpWwkzNW8FM= =gBHi -----END PGP SIGNATURE----- --4nx2de2bw7sbskt7--