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

Check that prepared statements are working as expected. #76

Closed
chanks opened this issue Jan 13, 2015 · 4 comments
Closed

Check that prepared statements are working as expected. #76

chanks opened this issue Jan 13, 2015 · 4 comments

Comments

@chanks
Copy link
Collaborator

chanks commented Jan 13, 2015

See #74.

@joevandyk
Copy link
Contributor

tanga_dev=# prepare test  as select 'now'::timestamptz;
PREPARE
tanga_dev=# execute test;
          timestamptz
-------------------------------
 2015-01-13 09:13:05.742936-08
(1 row)

tanga_dev=# execute test;
          timestamptz
-------------------------------
 2015-01-13 09:13:05.742936-08
(1 row)

Seems like there would be a problem if using prepared statements.

@joevandyk
Copy link
Contributor

Although:

tanga_dev=# prepare test  as select 'now()'::timestamptz;
PREPARE
tanga_dev=# execute test;
          timestamptz
-------------------------------
 2015-01-13 09:20:51.518569-08
(1 row)

tanga_dev=# execute test;
          timestamptz
-------------------------------
 2015-01-13 09:20:51.518569-08
(1 row)

I don't know much about prepared statements yet.

[edit]

I see, removing the quotes is the trick:

tanga_dev=# prepare test  as select now()::timestamptz;
PREPARE
tanga_dev=# execute test;
              now
-------------------------------
 2015-01-13 09:23:24.448843-08
(1 row)

tanga_dev=# execute test;
              now
-------------------------------
 2015-01-13 09:23:25.384618-08
(1 row)

@johto
Copy link

johto commented Jan 14, 2015

Yeah, the difference is that one is a function call evaluated during runtime, and the other one is a literal evaluated during prepare. If the problem can't be reproduced in Ruby, I'm guessing it doesn't do server-side prepared statements.

The cast to timestamptz for now() is unnecessary, since it's guaranteed to return a timestamptz.

@chanks
Copy link
Collaborator Author

chanks commented May 14, 2015

Going through old issues and can't replicate this one. I suppose the switch to now() fixed it. Thanks, though!

@chanks chanks closed this as completed May 14, 2015
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

3 participants