0

I want to insert some data into a Postgres DB using Sequel. I have pursued two approaches, none has yielded the results I want.

My first approach was "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

My second approach was "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
2
  • What results did you get, and what results did you expect? Commented Sep 8, 2016 at 1:29
  • I expected to insert the data into the DB. I check for evidence of the insert by querying the DB separately. The insert didn't happen Commented Sep 8, 2016 at 7:58

1 Answer 1

1

Simply following the code below worked for me:

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', updated_at: '2016-09-07 11:11:31')
connection.close

Changing the values for :created_at and :updated_at to store time stamps without time zones did the trick.

It is weird how Sequel wouldn't output an error to warn about this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.