psycopg / psycopg2

PostgreSQL database adapter for the Python programming language
https://www.psycopg.org/
Other
3.31k stars 503 forks source link

$$$ in string causing issues with execution #1704

Open rahul-vinaudit opened 3 months ago

rahul-vinaudit commented 3 months ago

This does not work for me

with connection.cursor() as cursor: query = "DO $$ BEGIN BEGIN INSERT INTO testtable2 (test1, test2, test3) VALUES (%s, %s, %s); END; END $$;" parameters = (333, 'STRING $$$ SOME STRING', 'Some string', ) cursor.execute(query, parameters) cursor.execute("COMMIT") connection.close()

But when I remove the $ sign in the string, it is working ?

STRING $$$ SOME STRING

or If I escape the $ it is working as well.

Like this works /root/test_bug2.py:20: SyntaxWarning: invalid escape sequence '\$' parameters = (333, 'STRING \$\$\$ SOME STRING', 'Some string', )

with connection.cursor() as cursor: query = "DO $$ BEGIN BEGIN INSERT INTO testtable2 (test1, test2, test3) VALUES (%s, %s, %s); END; END $$;" parameters = (333, 'STRING \$\$\$ SOME STRING', 'Some string', ) cursor.execute(query, parameters) cursor.execute("COMMIT") connection.close()

dvarrazzo commented 3 months ago

Does it work with psycopg 3?

dvarrazzo commented 3 months ago

PostgreSQL version: I'm using Yugabytes

I think it's a bug on their side.