Guest User

Untitled

a guest
Jun 12th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. # simple pg tests for dynamic column types
  2. require 'rubygems'
  3. require 'pg'
  4. require 'pp'
  5.  
  6. host = "localhost"
  7. port = "5432"
  8. dbname = "postgres"
  9. user = "user"
  10. pass = "pass"
  11.  
  12. conn = PGconn.open(:dbname => dbname, :user => user, :pass => pass, :host => host, :port => port)
  13.  
  14. # pp PGconn.conndefaults
  15.  
  16. res = conn.exec('SELECT now()::timestamp AS right_now')
  17.  
  18. # puts res.methods.sort
  19. puts res[0].inspect
  20.  
  21. puts "tuple_count = " + res.num_tuples.to_s
  22. puts "type oid = " + res.ftype(0).to_s
  23.  
  24. type = conn.exec("SELECT typname AS name FROM pg_type WHERE oid = #{res.ftype(0)}")
  25. puts "type = " + type[0][type.fields[0]].to_s
Add Comment
Please, Sign In to add comment