【发布时间】:2016-10-06 08:55:58
【问题描述】:
我想使用 Sequel 将一些数据插入 Postgres 数据库。我采用了两种方法,都没有达到我想要的结果。
我的第一个方法是“Querying in Sequel”:
connection = Sequel.connect('postgres://admin:admin@localhost:5432/test_tcp')
insert_values = connection["INSERT INTO cards (:card_number, :phone_number, :uuid, :created_at, :updated_at) VALUES (?)", '766877868', '256700000000', '9043', '2016-09-07 11:11:31 +0300', '2016-09-07 11:11:31 +0300']
insert_values.insert
connection.close
我的第二种方法是“Inserting Records”:
connection = Sequel.connect('postgres://admin:admin@localhost:5432/test_tcp')
cards = connection.from(:cards)
cards.insert(:id => 1, :card_number => "13668389", :phone_number => "256700000000", :uuid => "9014", :created_at => '2016-09-07 11:11:31 +0300', :updated_at => '2016-09-07 11:11:31 +0300')
connection.close
【问题讨论】:
-
你得到了什么结果,你期望得到什么结果?
-
我希望将数据插入数据库。我通过单独查询数据库来检查插入的证据。插入没有发生
标签: ruby postgresql sequel