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

SQL Syntax Errors referencing a $1 placeholder #13

Closed
afair opened this issue Sep 11, 2014 · 0 comments
Closed

SQL Syntax Errors referencing a $1 placeholder #13

afair opened this issue Sep 11, 2014 · 0 comments

Comments

@afair
Copy link
Owner

afair commented Sep 11, 2014

When running a query using an association, ActiveRecord has changed to use prepared statements with bind parameters, something like:

"select * from  comments where post_id = $1", [["post_id", 123]]

so when to_sql is called on the relation, the $1 is not yet interpolated.

Solution: use connection.unprepared_statement { to_sql } syntax to skip preparation. Cursor declaration includes preparation anyway.

@afair afair closed this as completed in e8630d5 Sep 11, 2014
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

1 participant