Skip to content

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

Open

Description

@merlindeep

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

Activity

  1. kisamoto commented on Jul 15, 2019

    @kisamoto

    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
    
  2. powerman commented on Jul 27, 2019

    @powerman

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

  3. kisamoto commented on Jul 28, 2019

    @kisamoto

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

  4. quenbyako commented on Sep 22, 2023

    @quenbyako

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions