GreenPlum DATE_PART function convert into Hive SQL - hive

I am migrating Greenplum to HiveSql but i could not able to find any such below kind of solution in google search. please help me.
DATE_PART('minute',ck_2::time - ck_1::time) gap_1_2
please help me , how do we convert above the statement to hivesql.

If i am not wrong ask here is time difference in minute for hive,
it can be achieved using unix_timestamp it covert time in second and then devide it by 60 and get time difference in minute
ie -
SELECT (( unix_timestamp(ck_2) - unix_timestamp(ck_1))/60 ) as gap_1_2

Related

Is there an sql script to get the date and time a query was run?

I wondered if anyone can help. I need to get the date and time an sql query was run. I would like the output to be in the following format; YYYY-MM-DDThh:mm:ss Does anyone know what sql to write get this information please?
Thanks
You can select the current timestamp in the query. The standard SQL for that is:
select . . ., current_timestamp
from . . .
Most databases support this. However, there are also bespoke methods such as getdate(), now() and sysdate.

How to Use decorators in STANDARD SQL

I want to recover the truncated data from a table in bigquery an hour back,
I found one of the solution in legacy SQL like below:
SELECT COUNT(*) FROM [PROJECT_ID:DATASET.TABLE#-3600000]
How to achieve the same in standard sql.
Thanks
See the FOR SYSTEM TIME AS OF documentation. You would want something like this:
SELECT *
FROM `project`.dataset.table FOR SYSTEM TIME AS OF
TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR)
Relative time decorator is not supported in standard sql yet. You can use absolute timestamp as the decorator in standard sql. Link from official Bigquery here.
EDIT
As per Elliott's response, its supported now in standard sql with different syntax.

Amazon redshift - extracting time from timestamp SQL error

I am trying to extract the time from a datetime column in my Amazon Redshift database (Postgresql 8.0). I have already referred to previous questions such as this. But I am getting an unusual error.
When I try:
SELECT collected_timestamp::time
or
SELECT cast(collected_timestamp as time)
I get the following error:
ERROR: Specified types or functions (one per INFO message) not supported on Redshift tables
The goal is to pull the time portion from the timestamp such that 2017-11-06 13:03:28 returns 13:03:28.
This seems like an easy problem to solve but for some reason I am missing something. Researching that error does not lead to anything meaningful. Any help is appreciated.
Note that Redshift <> PostgreSQL - it was forked from PostgreSQL but is very different under the hood.
You're trying to cast a timestamp value to a data type of "time" which does not exist in Redshift. To return a value that is only the time component of a timestamp you will need to cast it to a character data type, e.g.:
SELECT to_char(collected_timestamp, 'HH24:MI:SS');
There are a few ways, here is one i use:
SELECT ('2018-03-07 21:55:12'::timestamp - trunc('2018-03-07 21:55:12'::timestamp))::time;
I hope that helps.
EDIT: I have made incorrect use of ::time please see comments on other answer.

Convert DB2 SQL time (str) to time (HH:MM)

I´ve got the following table (column) in DB2:
TIME
04:30
05:00
...
This time is storaged as character Why someone did this is not clear to me. I would like to know how to convert this time into 'HH:MM' or 'HHMM' time format with DB2 SQL. The goal is to work with min(time) and max(time) afterwards. I haven´t been able to find an example here. Any hints?
Thank you!
(I hope the description is clearer now)
You can use the following SQL statement if you have not tried it already:
'SELECT CONVERT(TIME, '06:30');'

Apache Phoenix Current Time

I am trying Apache Phoenix with Hbase. When I run try to get current time using select current_time(), its giving me some weird value. (292278994-08-17 07:12:55.807). Similarly for current_date() or now() query. I am not able to understand what does this mean, and how to get the current time (as we get from mysql now() function). Because of this I am unable to set the data type for view column as Date or Timestamp, as its doing some weird conversion.
Can anyone help me figure out a solution for this.
As a workaround, you can do select current_time() from any_table which will return the expected result
This is fixed in 4.6.1 and 4.7 version of phoenix.
https://issues.apache.org/jira/browse/PHOENIX-2611