Skip to content

Simplier prepared statement #12

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
wavded opened this issue Jan 27, 2011 · 3 comments
Closed

Simplier prepared statement #12

wavded opened this issue Jan 27, 2011 · 3 comments

Comments

@wavded
Copy link

wavded commented Jan 27, 2011

You may have already dealt with this but it would be helpful to just use ? like in perl for a placeholder instead of $1 $2 etc... easier to type and don't have to worry about numbering. Just a thought.

@brianc
Copy link
Owner

brianc commented Jan 28, 2011

So I've done some reading & it seems like the '?' syntax is only for drivers which do client-side substitution of prepared statement values. The "$1" "$2" syntax is the officially supported syntax of PostgreSQL. What driver did you previously use which used the '?' syntax? I'll dig deeper into how that driver was implemented & see why/how they used ?'s.

@wavded
Copy link
Author

wavded commented Jan 28, 2011

I've used DBI:Pg in Perl (http://search.cpan.org/~rudy/DBD-Pg-1.32/Pg.pm)

But now that you mention it, I think they do some server-side substitution before it gets to the database. I didn't know that was the internal syntax so maybe that's good to keep, it's just nicer to write:
...
sql += field + " = ? "
...

Then:
...
sql += field + " = $" + i
...

And have to keep track of the numbers, could be more error prone but not the end of the world either.

@brianc
Copy link
Owner

brianc commented Feb 3, 2011

I'm going to close this one for now. Don't think adding ?'s instead of $1's is really the right move since the prepared statement happens on the server and the server demands $1 style parameters. In fact, I tried using ?'s and the server got angry at me. :)

Still considering implementing ? and $1 style replacement on the client side before sending to Postgres as an option, but it would have to be explicit with some pg.escape(string, [params]) type of function.

brianc added a commit that referenced this issue Dec 18, 2019
Fix typo: itterate -> iterate
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants