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.5K Connect
- 1.2K Connectors
- 296 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 614 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 729 Beast Mode
- 53 App Studio
- 40 Variables
- 677 Automate
- 173 Apps
- 451 APIs & Domo Developer
- 45 Workflows
- 8 DomoAI
- 34 Predict
- 14 Jupyter Workspaces
- 20 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 121 Manage
- 118 Governance & Security
- Domo Community Gallery
- 32 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive