Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NamedQuery error when use PostgreSQL type cast ::int #428

Open
merlindeep opened this issue Jul 9, 2018 · 4 comments
Open

NamedQuery error when use PostgreSQL type cast ::int #428

merlindeep opened this issue Jul 9, 2018 · 4 comments

Comments

@merlindeep
Copy link

When I use NamedQuery for PostgreSQL and use type cast ::int in query:

SELECT (d.categories->>0)::int AS category_id
FROM some_table d
WHERE id =:id

I get error:

error="pq: syntax error at or near \":\""

if I use CAST

SELECT CAST(d.categories->>0 AS integer) AS category_id
FROM some_table d
WHERE id =:id

query works fine

@kisamoto
Copy link

kisamoto commented Jul 15, 2019

Just spotted this but I'm guessing it's because you're using a NamedStmt which requires you to double escape all :. Your generated query will only be providing one : to PostgreSQL and then failing.

Try changing to:

SELECT (d.categories->>0)::::int AS category_id

@powerman
Copy link

@kisamoto Thanks. Is this way to double-escape : documented?

@kisamoto
Copy link

@powerman I didn't find it in the docs, instead I noticed it searching for a similar problem that led me to #91

@quenbyako
Copy link

quenbyako commented Sep 22, 2023

@kisamoto
Try changing to:

SELECT (d.categories->>0)::::int AS category_id

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants