Created
May 4, 2016 08:07
-
-
Save llaine/673969a8b87f5f0355970df9c69e7e6f to your computer and use it in GitHub Desktop.
prepared statement with rails and postgresql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| connection = ActiveRecord::Base.connection.raw_connection | |
| => #<PG::Connection:0x00563e2c718098> | |
| [30] pry(main)> connection.prepare('user_id', "select * from users where id = $1") | |
| PG::DuplicatePstatement: ERROR: prepared statement "user_id" already exists | |
| from (pry):35:in `prepare' | |
| [31] pry(main)> st = connection.exec_prepared('user_id', [786]) | |
| => #<PG::Result:0x00563e26a5bd78 status=PGRES_TUPLES_OK ntuples=1 nfields=29 cmd_tuples=1> | |
| [32] pry(main)> st.each_row do |x| | |
| [32] pry(main)* p x | |
| [32] pry(main)* end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment