PQexecParams and "SET TIME ZONE $1" gets 'syntax error at or near "$1" at character 15'

From: <ma(dot)sao(at)msa(dot)hinet(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: PQexecParams and "SET TIME ZONE $1" gets 'syntax error at or near "$1" at character 15'
Date: 2024-11-23 15:01:04
Message-ID: 837985448.725696.1732374064323@sg2000-ap-3
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


I get get this same error

syntax error at or near "$1" at character 15

if I feed "const char *command" with the following texts.

SET TIME ZONE $1
SET TIME ZONE $1::TEXT

For some reasons, I can not add quotes around $1 as follows.

SET TIME ZONE '$1'
SET TIME ZONE '$1'::TEXT

Statements like "SELECT ... WHERE $1=..." have been working flawlessly.

It looks like PQexecParams doesn't handle statement with "SET ... $1".

Are there workarounds for me or PQexecParams needs improvement?

Thank you!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2024-11-23 15:57:49 Re: PQexecParams and "SET TIME ZONE $1" gets 'syntax error at or near "$1" at character 15'
Previous Message Steeve Boulanger 2024-11-23 13:16:44 Re: Database stats ( pg_stat_database.stats_reset ) get reset on daily basis - why?