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

Badly formatted TIMESTAMPs #23

Open
vanetten opened this issue Oct 20, 2015 · 0 comments
Open

Badly formatted TIMESTAMPs #23

vanetten opened this issue Oct 20, 2015 · 0 comments

Comments

@vanetten
Copy link

I was getting weird results from a TIMESTAMP column.
After some research, came up with the following workaround.

Under the covers, BigQuery stores timestamps as a UNIX timestamps, not date/time strings as you get from the BigQuery console.

"TIMESTAMP data types can be described in two ways: UNIX timestamps or calendar datetimes. BigQuery stores TIMESTAMP data internally as a UNIX timestamp with microsecond precision.
UNIX timestamps
A positive or negative decimal number. A positive number specifies the number of seconds since the epoch (1970-01-01 00:00:00 UTC), and a negative number specifies the number of seconds before the epoch. Up to 6 decimal places (microsecond precision) are preserved."

To resolve this, I told the table's model to interpret the TESTDATE column as a decimal,
then I converted the UNIX timestamp to a UTC date/time string.

class << columns_hash['TESTDATE']
def type :decimal
end
end

def TESTDATE
Time.at(self[:TESTDATE]).utc
end

Now the TESTDATE(s) come out correctly.

s = Table.find(id)

before:
s.TESTDATE
=> Sat, 01 Jan 1972 00:00:00 UTC +00:00

after:
s.TESTDATE
=> 2000-10-30 00:00:00 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant