Sum ( Extract ( ) ) using RedShift
Using RedShift,,, i know that EXTRACT ( minute from date1) will give me the minute from date1 (18:03.94 returns 3)
Ok,,, so now in my RedShift i said
SELECT
SUM( (EXTRACT(hour from date1-date2)*60) + extract(minute from date1-date2) )
So in my POSTGRES db, that returns everything great in total minutes.. Here's what i am seeing in redshift (hopefully i am coding it wrong).
Redshift gives me the full number of minutes between date1 and date2 from the extract(minute from date1 - date2). So instead of < 60 being the result, it is the actual number of minutes between the two dates. Which is what i was trying to get by adding in the extract(hour) * 60.
So now over in POSTGresql, using EXTRACT() i have to keep the HOUR*60, but the RedShift manipulates the EXTRACT( minute ) differently. Has anyone else seen this before?
SUM((extract(hour from end_dt - start_dt)*60) + extract(minute from end_dt - start_dt)) DURATION, In POSTGRESql this is accurate
however that pasted into RedShift returns accurante+(hour*60). So if the results was 188 minutes, the DB returns 188, however redshift returns 180 + 188 (3hours *60 + 188 minutes = 368). This was CRAZY and i hope someone can test this on their system and validate my results, as this will need to be something handled whenever we create dataflows.
Thanks, and sorry if I wrote this horribly.
Best Answer
-
Hi,
if what I think you want to do is what you want to do (calculate number of minutes between two timestamps) then I do not entirely understand why you cant just delete the first *60 part to get the right result? You definitely cant use the same code for this. Two different query languages return different results when using the same code, that is in itself not surprising.
When you load data into Domo, the language that would have been used to query or manipulate the data in the original source no longer matters. If you load an excel file and start querying it in Domo using SQL, writing code in VBA will not give you anything except for error messages.
I am not working with Postgre, but for Redshift you could just try using DATEDIFF to calculate the minute difference directly. Also shorter ?
Keep in mind that the order of the dates in DATEDIFF matters, so you might want to use ABS() or make sure it is set in a way that it never returns negative numbers.
HTH JHL
0
Answers
-
Hi,
if what I think you want to do is what you want to do (calculate number of minutes between two timestamps) then I do not entirely understand why you cant just delete the first *60 part to get the right result? You definitely cant use the same code for this. Two different query languages return different results when using the same code, that is in itself not surprising.
When you load data into Domo, the language that would have been used to query or manipulate the data in the original source no longer matters. If you load an excel file and start querying it in Domo using SQL, writing code in VBA will not give you anything except for error messages.
I am not working with Postgre, but for Redshift you could just try using DATEDIFF to calculate the minute difference directly. Also shorter ?
Keep in mind that the order of the dates in DATEDIFF matters, so you might want to use ABS() or make sure it is set in a way that it never returns negative numbers.
HTH JHL
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive