TO_CHAR(order_placed_at_ltz,'YYYY-MM') = TO_CHAR(NOW(),'YYYY-MM')
it gives me this error:
ERROR: Specified types or functions (one per INFO message) not supported on Redshift tables.
I want to get the orders placed for this month according to some queries that I made and I put the TO_CHAR function in a WHERE condition .
According to Redshift documentation on date and time functions, it does not have a now() function. Use getdate() or current_date() function instead.
Related
I am currently trying to calculate due by dates in a table by adding the sla time to the time the request was created. From what I am able to understand, the way to go around this is to create a table with the work days and hours and query that table to find the due date. However, redshift does not allow one to declare variables. I was wondering how I would go around creating a work hour table in redshift and if that is not possible, how I would calculate the due date by other means. Thanks!
It appears that you would like to provide a timestamp and then calculate the timestamp that is 'n work hours later', most probably taking into account certain rules such as:
Weekdays: 9am-5pm
Weekends: No Hours
Holidays: Occasional weekdays with No Hours
This could be done by Creating a scalar Python UDF - Amazon Redshift that would be passed a 'start' timestamp and a number of hours, and would return the 'end' timestamp.
Please note that Scalar UDFs cannot access tables or 'call outside' of Redshift, so it would need to be self-contained.
There is code on the web that shows How to find the number of hours between two dates excluding weekends and certain holidays in Python? BusinessHours package - Stack Overflow. You would need to modify such code to specify the duration rather than finding the duration.
The alternate method of "creating a work hour table" would work well when trying to find the number of work hours between two timestamps but would be a bit harder when trying to add workhours to a timestamp.
I am trying to use current_date function in my BQ query to fecth today's data, but it was not working. After debugging I found out this function returns yesterday's data.
Unfortunately I am not able to add screenshot here.
Below is the query that I ran
Select current_date as the_date
result = 2020-08-20
it should be 2020-08-21
Any idea how to resolve this or how to fetch current datein big query
If you don't specify a time zone, it uses the default for your project. I would guess your default is mis-configured.
Running these queries returns different results.
select current_date('US/Pacific') as the_date
select current_date('Australia/Melbourne') as the_date
Allowable time zone values are here, also on how to use the current_date().
I have a complex query which gives multiple rows for some two dates- starting date and end date.
Now I want to create a function so that I can return multiple rows for a different combination of dates.
CREATE FUNCTION submit_cohort(DATE, DATE)
RETURNS TABLE(Month VARCHAR(10), Name1 VARCHAR(20), Name2 VARCHAR(20), x INTEGER)
STABLE
AS $$
SELECT
to_char((date + interval '330 minutes')::date, 'YYYY/MM') "Month",
Name1,
Name2,
count(*) "x"
FROM xyz
WHERE date > $1
AND date < $2
GROUP BY 1,2,3
ORDER BY 1,2,3
END
$$ LANGUAGE sql;
I ran this query. It says:
Amazon Invalid operation: syntax error at or near "TABLE"
In Redshift, you can define only scalar functions, i.e. those which return a single value. Set based functions (those which return tables) are not supported in Redshift unfortunately.
Possible reason is that Redshift is a distributed database and functions are running on the compute nodes in parallel, independently of each other. Set based functions need to be able to read data from the database, but there is a chance that some data sits on the given node while another portion sits on another node. Such function can't run on a specific compute node independently. You would have to run such function on the master node only. Which you didn't want to do as it's against the whole concept of parallelism.
Try to express the same logic in a SQL query. From your code it seems like it can work as a regular query/subquery.
I am using AWS QuickSight to create some simple reports.
Based on the dates column I need to find min of date group by particular
dimension.
I am using option "Add calculated field" for this where I
am applying "min" function to date column. This particular column is
already marked as "measure" and it is of type Date
The expression looks something like min("periods") OR min({periods}) OR min(periods). None of these works.
While creating this calculated field I am getting following error
At least one of the arguments in this function does not have correct
type. Correct the expression and choose Create again.
This is because you cannot take the minimum of a date if the date is stored in as a DATETIME.
extract() the parts of the date you want and concatenate() them back together as a string, then use the toInt() or toDecimal() function to create a data-type compatible with the min() function.
I use to to this extract('YYYY',date) * 365 + extract('MM',date) * 31 + extract('DD',date) and then max on the result
i'm trying the new Power BI (Desktop) to create a barchart that shows me the duration in days for the delivery of an order.
I have 2 files. 1 with the delivery data (date, barcode) and another file with the deliverystatusses (date, barcode).
I Created a relation in the powerBI relations tab on the left side to create a relation on barcode. 1 Delivery to many DeliveryStatusses.
Now I want to add a column/measure to calculate the number of days before a package is delivered. I searched a few blogs but with no succes.
The function DATEDIFF is only recognized in a measure, and measures seem to work on table date, not rowdata. So adding a column using the DATEDIFF function doesn't work.
Adding a column using a formula :
Duration = [DeliveryDate] - Delivery[OrderDate]
results in an error that the right side is a list (It seems the relationship isn't in place)?
What am I doing wrong?
You might try doing this in the Query window instead since I think each barcode has just one delivery date and one delivery status. You could merge the two queries into a single table. Then you wouldn't need to worry about the relationships... If on the other hand you can have multiple lines for each delivery in the delivery status table, then you need to get more fancy. If you're only interested in the last status (as opposed to the history of status) you could again use the Query windows to group the data. If you need the full flexibility, you'd probably need to create a Measure that expresses the logic you want.
The RELATED keyword is used to reference another table. Update your query as follows and it should work.
Like this:
Duration = [DeliveryDate] - RELATED(Delivery[OrderDate])