The datetime type is not retained when the query result is saved as csv - google-bigquery

I am using the following query to fetch some results from a bigquery dataset:
SELECT name, TIMESTAMP(due) AS due, TIMESTAMP(start) AS start,
FROM myBigQueryTable
Then, I save the query result as csv. However, the due and start columns do not have datetime type in the csv file and displays a value like:
1.41E+09
instead of this:
2014-12-24 00:00:00 UTC
If I only use DATE instead of TIMESTAMP then the problem disappears, however I also need the time info. How can I resolve this issue?

This is a known problem with BigQuery UI and it is tracked here: https://issuetracker.google.com/issues/36614760.
I have the fix ready and it will go out into production within few weeks.

Related

Get date today, if no data - get data from yesterday (dynamic)

I have such an issue. I have a report that is built around today's date. We see data only from today. On Hand units from today.
However, we have many import issues and sometimes import fails and there is no data in this report. I was wondering if there may be a way to make it dynamic like to use MAX function with getdate() or anything similar. I always want to see data from today, however if there is no data available for today I would like to see the data from yesterday. If not from yesterday from a day before yesterday.
I need to change the date logic to just pull the data for the max date.
Does someone know how it can be done?
where sku.ohpost = cast(getdate()as date)
try this If column sku.ohpost type is date
where sku.ohpost = ( select max(sku.ohpost ) from mytable)

On a redash dashboard, what causes "Error running query: 100035 (22007): Timestamp 'd_yesterday' is not recognized"?

On a Redash application instance backed by a Snowflake database, I've got a dashboard set up with a number of queries, each of which take a parameter of type date named startDate.
Each of my queries are coded to apply the dashboard's selected date via WHERE clauses like:
WHERE created_at >= '{{ startDate }}'
In most cases, this is working fine.
However, when on my dashboard, for the startDate parameter, I select the special value Yesterday (instead of a specific date), some (but not all) of my queries display an error instead of displaying any data: Error running query: 100035 (22007): Timestamp 'd_yesterday' is not recognized.
What does this error mean, and how can I fix it?
This problem occurs when on the affected queries, the parameter still has its default type of text, instead of having been changed to type date.
The error is occurring because choosing the special date value "Yesterday" on the dashboard only works with date-type parameters -- not text-type parameters.
Changing the parameter type to date on each of the individual queries, saving those changes, and then refreshing the dashboard, should fix the problem.

While sending data in JSON, the date changes to previous day

Saving the data in one function call, where I am sending the data as 2019-02-01T00:00:00.000Z but the fiddler shows the different date in JSON as 2019-01-31T18:30:00.000Z. I am not aware that why it is giving the difference of 5 hrs 30 minutes.
On the local case, date saved in the database is 01-02-2019, while on production environment the previous date is getting saved in the table records.
Thanks in advance. Please help me with the solutions.

How to save date into database with current time?

I have a table in database, one of the row adds add while something was done/acomplished. And it works fine. But.. it doesn't add current time. When I prints out date from db, it shows 2016-12-13 00:00. Instead of for example 2016-12-13 15:32. How do I add current time?
This is how my sql looks
[example_date] DATE NOT NULL,
The date data type does not have a time component. You want either datetime or datetime2 (or perhaps smalldatetime):
example_datetime DATETIME NOT NULL,
You can review the documentation for the various date/time data types here.

BigQuery: Why does Table Range Decorators return wrong result sometimes?

I've been using the Table Range Decorators feature daily since May in order to only query the data from the last 7 days in some of my tables.
Since 2 weeks, I've noticed that sometimes some data is missing when I use that feature. For example, if do a query to get the results for the last 7 days (by adding "#-604800000--1" to table), some data will be missing as opposed to if I query on the whole table (without a table decorator).
I wonder what could explain this and if there is a fix coming soon to address this?
If this can help the BigQuery team, I've noticed that when using Table Decorators some data was missing for us for October 16th between around 16:00 and 20:00 UTC time.
For the BigQuery team here are 2 jobs ids where some data is missing: job_-xtL4PlIYhNjQ5weMnssvqDmd6U , job_9ASNxqq_swjCd1eMmiQ6SmPpxlQ
and 1 job id where data is correct(without decorators): job_QbcRwYGbQv0BZdHreQEvRlYh-mM
This is a known issue with table decorators containing a time range. Due to a bug in BigQuery, it is possible for certain time ranges to omit data that should be included within the time range.
We're working on a fix and plan to have it released next week. After this fix is deployed time range decorators should again work as expected.