Skip to content

Instantly share code, notes, and snippets.

@kuldeepaggarwal
Last active December 31, 2015 23:19
Show Gist options
  • Save kuldeepaggarwal/8059768 to your computer and use it in GitHub Desktop.
Save kuldeepaggarwal/8059768 to your computer and use it in GitHub Desktop.
AR PG timestamp error #13402
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.0.2'
gem 'pg'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
encoding: 'utf8',
database: 'kd_test',
username: 'postgres',
password: '',
host: 'localhost'
)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :sql_arrays, force: true do |t|
t.timestamp :timestamps, array: true, default: []
t.date :dates, array: true, default: []
t.timestamps
end
end
class SqlArray < ActiveRecord::Base
end
class BugTest < MiniTest::Unit::TestCase
def test_multiline_insert_sql
current_time = Time.new
a = SqlArray.create(timestamps: [current_time], dates: [Date.today])
assert_equal [current_time], a.timestamps
end
end
OutPut:
-- create_table(:sql_arrays, {:force=>true})
D, [2013-12-21T00:32:57.343735 #10082] DEBUG -- : (5.7ms) DROP TABLE "sql_arrays"
D, [2013-12-21T00:32:57.353082 #10082] DEBUG -- : (8.5ms) CREATE TABLE "sql_arrays" ("id" serial primary key, "timestamps" timestamp[] DEFAULT '{}', "dates" date[] DEFAULT '{}', "created_at" timestamp, "updated_at" timestamp)
-> 0.0484s
Run options: --seed 32642
# Running tests:
D, [2013-12-21T00:32:57.377630 #10082] DEBUG -- : (0.2ms) BEGIN
D, [2013-12-21T00:32:57.388388 #10082] DEBUG -- : SQL (5.9ms) INSERT INTO "sql_arrays" ("created_at", "dates", "timestamps", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["created_at", 2013-12-20 19:02:57 UTC], ["dates", [Sat, 21 Dec 2013]], ["timestamps", [2013-12-21 00:32:57 +0530]], ["updated_at", 2013-12-20 19:02:57 UTC]]
D, [2013-12-21T00:32:57.389482 #10082] DEBUG -- : (0.5ms) COMMIT
.
Finished tests in 0.036193s, 27.6297 tests/s, 27.6297 assertions/s.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment