public inbox for [email protected]
help / color / mirror / Atom feedFrom: Jacobo Sánchez López <[email protected]>
To: [email protected]
Subject: Substitution of convert function "{fn CONVERT(1, SQL_BIGINT)}" to text litreral '1'
Date: Mon, 16 Jan 2023 16:42:06 +0100
Message-ID: <[email protected]> (raw)
Hi
I am doing some tests and found that when using a query with the
convert function like
SELECT SUM({fn CONVERT(1, SQL_BIGINT)})
It gets translated to
SELECT SUM('1')
Which fails due to the aggregation function receiving a text
literal instead of a number.
I have narrowed down to this line in convert.c
(https://git.postgresql.org/gitweb/?p=psqlodbc.git;a=blob;f=convert.c;h=d94fdb685df0a3430a13650f5140b...)
deciding to add the quotes:
5743 else if (isdigit((unsigned char) *pptr))
5744 add_quote = TRUE;
How expected is that convert function to produce a text literal
which makes the query to fail?
The simpliest way to reproduce it I found is with a python script
using a DSN called PostgreSQL35W (tested with version 13.02.0000):
importpyodbc
query= "SELECT SUM({fn CONVERT(1, SQL_INTEGER)})"
connection= pyodbc.connect('DSN=PostgreSQL35W',autocommit=True)
cursor= connection.cursor()
cursor.execute(query)
forrowincursor.fetchall():
print(row)
Best regards,
Jacobo
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Substitution of convert function "{fn CONVERT(1, SQL_BIGINT)}" to text litreral '1'
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox