Cannot use question mark as prepared statement placeholder?
See original GitHub issueI am converting an existing project from MySQL to Postgres. There are quite a few raw SQL literals in the code that use ?
as a placeholder, e.g.
SELECT
id
FROM
users
WHERE
name = ?
But I get this error:
DB query error: error: operator does not exist: character varying = ?
I don’t want to convert all my existing SQL from ?
to postgres-style operators like $1
. Is there some way of having node-postgres accept the question marks instead, or a utility that can convert to postgres style params?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Prepared statements: Using unnamed and unnumbered ...
The problem with this syntax arises when I try to insert a large number of rows in one statement, for a 10,000 rows...
Read more >PDO::prepare - Manual - PHP
Both named and question mark parameter markers cannot be used within the same statement template; only one or the other parameter style.
Read more >Prepare a statement - IBM
First, if it is a SELECT statement, it cannot include the INTO variable clause. ... Only the PREPARE statement can specify question mark...
Read more >Prepared Statement Question Mark within WHERE LIKE '%?%'
When writing a prepared statement in a Base macro, I can't seem to replace the question mark within WHERE LIKE '%?%'.
Read more >PDO::prepare() - micmap.org
parameter markers for which real values will be substituted when the statement is executed. You cannot use both named and question mark parameter...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
'shouldn''t'
, if you’re escaping, but again: don’t. It’s a terrible idea. Use parameters. You don’t have to write them manually: https://gist.github.com/charmander/8f7b05f8d2b2e4e3c190c7a9e1bec1f2Aside: a properly fair comparison would be:
Solution: don’t do that.
@gajus MySQL’s string escaping is non-standard and won’t work with PostgreSQL:
The entire sqlstring approach is a bad one in the first place, though. Use real parameters, please.