Ruby读取PostgreSQL数据库

1.安装PG模块

gem install pg


2.访问PostgreSQL

require 'pg'

conn = PGconn.open(:dbname => 'test')

res  = conn.exec('SELECT 1 AS a, 2 AS b, NULL AS c')

res.getvalue(0,0) # '1'

res[0]['b']       # '2'

res[0]['c']       # nil



~~THE END~~


尹曙光

你可能感兴趣的:(PostgreSQL,Ruby,postgres)