19

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.

Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169
newleaf
  • 2,257
  • 8
  • 32
  • 52

2 Answers2

38

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';
Yusuf Hassan
  • 1,933
  • 1
  • 12
  • 21
4
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.

Golokesh Patra
  • 578
  • 8
  • 24