# -*- encoding : utf-8 -*-
require 'pg'
PG_CONN = PG.connect(
dbname: 'minicron',
host: '127.0.0.1',
port: 5432,
user: 'postgres',
password: 'www.pp.c0m'
)
PG_CONN.prepare(
'statement1',
"select * from jobs"
)
PG_CONN.prepare(
'statement2',
"update public.jobs set job_hash = $1 where name is not null and command = $2"
)
aa = PG_CONN.exec_prepared('statement1')
aa.each do |a|
PG_CONN.exec_prepared('statement2',[a['job_hash'], a['command']])
end
本文通过一个Ruby脚本示例展示了如何连接到PostgreSQL数据库并执行预编译的SQL语句,包括查询所有作业记录及更新作业哈希。
598

被折叠的 条评论
为什么被折叠?



