21

I'm quite new to Redshift SQL.

    select *  from myredshift_tbl 
    where local_date between \'2016-01-01\' and \'2017-02-01\'; 

But got this error:

[amazon][500310] invalid operation syntax error at or near "\". I believe Redshift use single quote and I need to escape single quote.

3
  • 2
    Delete the backslash... Commented Jul 13, 2017 at 17:52
  • The backslashes are unnecessary. Remove them. Commented Jul 13, 2017 at 17:52
  • Please consider accepting an answer if you are satisfied with it. It will help other users who find this question. Commented Jan 31, 2018 at 16:51

2 Answers 2

39

If the column local_date is in date format, use:

select *  from myredshift_tbl 
    where local_date between '2016-01-01' and '2017-02-01';

If the column local_date is timestamp:

select *  from myredshift_tbl 
        where local_date between '2016-01-01 00:00:00' and '2017-02-01 23:59:59';
Sign up to request clarification or add additional context in comments.

1 Comment

What happens if the lower and upper bound are reversed?
5
SELECT * FROM schemaName.TableName WHERE datetime > '2017-02-09 
00:00:00' AND datetime < '2017-06-09 00:00:00';

The above query Works with Redshift to fetch all the entries in a table.

NOTE: The table I applied the query on had column/field 'datetime' of type 'timestamp'.

I tested this query on Redshift with the help of Workbench J.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.