Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue getting TIMESTAMP and TIMESTAMPTZ columns from database #6

Open
cyclotron3k opened this issue Nov 3, 2022 · 0 comments · May be fixed by #7
Open

Issue getting TIMESTAMP and TIMESTAMPTZ columns from database #6

cyclotron3k opened this issue Nov 3, 2022 · 0 comments · May be fixed by #7

Comments

@cyclotron3k
Copy link
Contributor

cyclotron3k commented Nov 3, 2022

If Postgres returns a timestamp with microsecond precision (e.g. 2022-11-03 14:31:05.112156) or timezone information (1999-12-31 23:59:59+00) it causes the following lines in db-postgres-0.7.0/lib/db/postgres/native/types.rb:105 to blow up:

parts = string.split(/[\-\s:]/)
return Time.utc(*parts)

Note: Postgres will truncate trailing zeroes, so if you insert a timestamp with 0 milliseconds, Postgres will return a timestamp without a decimal point and this issue will not be triggered.

Full test case:

Sync do
	session = client.session

	session.clause("CREATE TABLE IF NOT EXISTS")
		.identifier(:users)
		.clause("(")
			.identifier(:a_timestamp).clause("TIMESTAMP NOT NULL")
		.clause(")")
		.call

	session.clause("INSERT INTO")
		.identifier(:users)
		.clause("VALUES (NOW())")
		.call

	result = session.clause("SELECT * FROM").identifier(:users).call

	puts "Result: #{result.to_a}"
	puts "Done"

rescue => e
	puts "#{e.class}: #{e.message}"
	puts e.backtrace
ensure
	session.close
end

Output:

ArgumentError: invalid value for Integer(): "05.112156"
/usr/local/bundle/gems/db-postgres-0.7.0/lib/db/postgres/native/types.rb:105:in `utc'
/usr/local/bundle/gems/db-postgres-0.7.0/lib/db/postgres/native/types.rb:105:in `parse'
/usr/local/bundle/gems/db-postgres-0.7.0/lib/db/postgres/native/result.rb:87:in `block in cast!'
/usr/local/bundle/gems/db-postgres-0.7.0/lib/db/postgres/native/result.rb:85:in `times'
/usr/local/bundle/gems/db-postgres-0.7.0/lib/db/postgres/native/result.rb:85:in `cast!'
/usr/local/bundle/gems/db-postgres-0.7.0/lib/db/postgres/native/result.rb:96:in `block in each'
/usr/local/bundle/gems/db-postgres-0.7.0/lib/db/postgres/native/result.rb:95:in `times'
/usr/local/bundle/gems/db-postgres-0.7.0/lib/db/postgres/native/result.rb:95:in `each'
/usr/local/bundle/gems/db-postgres-0.7.0/lib/db/postgres/native/result.rb:115:in `to_a'
test.rb:36:in `block in <main>'
/usr/local/bundle/gems/async-2.2.1/lib/async/task.rb:107:in `block in run'
/usr/local/bundle/gems/async-2.2.1/lib/async/task.rb:243:in `block in schedule'

async 2.2.1
db-postgres 0.7.0
Ruby 3.1
Postgres 13
Debian GNU/Linux 11

@cyclotron3k cyclotron3k changed the title Issue getting Timezone column from database Issue getting Timestamp column from database Nov 4, 2022
@cyclotron3k cyclotron3k changed the title Issue getting Timestamp column from database Issue getting TIMESTAMP and TIMESTAMPTZ columns from database Nov 4, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 8, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 8, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 8, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 9, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 9, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 9, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 11, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 12, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 25, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 25, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 25, 2022
cyclotron3k added a commit to cyclotron3k/db-postgres that referenced this issue Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant