8000 Raw SQL converts number placeholders to strings · Issue #509 · romeerez/orchid-orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Raw SQL converts number placeholders to strings #509

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

Closed
IlyaSemenov opened this issue May 12, 2025 · 1 comment
Closed

Raw SQL converts number placeholders to strings #509

IlyaSemenov opened this issue May 12, 2025 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@IlyaSemenov
Copy link
Contributor

The documentation makes it think that one can pass numbers to SQL query:

sql<boolean>({
  raw: '$$column = random() * $value',
  values: {
    column: 'someTable.someColumn',
    one: value,
    two: 123, // <--------- here
  },
})

However, that's not really so. Passing numbers silently converts them to strings, and breaks queries expecting proper numbers. For example:

console.log((await db.$query`select substring('foobar', ${4}) as bar`).rows[0])
// Result: { bar: null }
// Expected: { bar: 'bar' }

I'm not sure if that's a bug in Orchid or it's how the upstream Postgres bindings behave. If it's the latter, I believe that should better be clearly mentioned in the documentation.

  • orchid-orm 1.49.0
  • pg 8.13.1
@romeerez romeerez added the documentation Improvements or additions to documentation label May 25, 2025
@romeerez
Copy link
Owner

The driver authors say that's an expected behavior and it's converted to string by the database:

brianc/node-postgres#2674 (comment)

porsager/postgres#842

I added a note to the docs.

You should mark it as int explicitly ${4}::int.

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

No branches or pull requests

2 participants
0