Search code examples
pythonsqlimpala

SQL (Impala) query syntax error for timestamp range


I am using the following query to find the data given the timestamp constraint:

query = 'select my_id, my_ts from my_table limit 100 where my_ts >  "2016-05-13 00:00:00"'
cursor = impala_con.cursor()
cursor.execute('USE my_database')
cursor.execute(query)

But get the following error:

HiveServer2Error: AnalysisException: Syntax error in line 1:
...my_ts from my_table limit 100 where my_ts >  "201...
                             ^
Encountered: WHERE
Expected: AND, BETWEEN, DIV, ILIKE, IN, IREGEXP, IS, LIKE, LIMIT, NOT, OFFSET, OR, ORDER, REGEXP, RLIKE, UNION

CAUSED BY: Exception: Syntax error

Does anyone know what I did wrong? Thanks!


Solution

  • According to the documentation you need to specify limit 100 after the where clause.

    query = 'select my_id, my_ts from my_table where my_ts >  "2016-05-13 00:00:00" limit 100'