Unload with timestamp filter

0

I was attempting to unload all data prior to 2017 from a database and hit what seems to be a bug...

my query was:

unload ('select * from traffic where timestamp < '2017-01-01' order by timestamp asc')
to 's3://xxx/export/unload/2019-01-22-3/'
iam_role 'arn:aws:iam::xxx:role/xxx'
delimiter as ','
addquotes
escape
manifest;

what I ended up with was only data prior to 2015, which I assume is a result of the date being evaluated as subtraction and looking at the query in the inspector:

unload ('select * from traffic where timestamp < 2017-01-01') to 's3://xxx/export/unload/2019-01-22/' iam_role '' delimiter as ',' addquotes escape allowoverwrite manifest

已提問 5 年前檢視次數 798 次
3 個答案
0
已接受的答案

It's likely that the backslash escape is being stripped by something that handles the query text before the query gets to Redshift.

Try doubling up the quotes instead as that also works.

unload ('select * from traffic where timestamp < '''2017-01-01'' order by timestamp asc')…
已回答 5 年前
0

which I assume is a result of the date being evaluated as subtraction

(lols!! I shouldn't laugh, but that is funny =-)

Maybe try using DATE_CMP() and seeing if the literal in the function is interprented correctly?

I would try it myself but I do not have access to a cluster.

Toebs2
已回答 5 年前
0

One general approach to avoid bugs or limitations in the select clause of the unload statement is to define a view where the view definition is what you want to unload, then refer to the view in the unload statement, e.g.:

create view #vname as
select * from traffic where timestamp < 2017-01-01 order by timestamp asc
;

unload (select * from #vname) to ..
;

Edited by: karbjonn on Jan 29, 2019 12:38 AM
Removed the quotes around the date criteria, and the unload select clause, as on posting the original message AWS gets confused and do not display the statements correctly. Of course, in real life, quotes must be added.

已回答 5 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南