1

I'm trying to do a query similar to this:

ctx = snowflake.connector.connect(
          host=host,
          user=user,
          password=password,
          account=account,
          warehouse=warehouse,
          database=database,
          schema=schema,
          protocol='https',
          port=port)

## Create a cursor object.
cur = ctx.cursor()

## Execute a statement that will generate a result set.
sql = "select * from t"
cur.execute(sql)

My query looks something like this:

select NUMBER, ID, DATE, CODE from DATABASE.SCHEMA.TABLE
where (cast(CODE as string) like 'ABC12%'
and (DATE < '2021-12-31' and DATE >= '2021-10-01')

I'm getting this error:

ProgrammingError: 001003 (42000): SQL compilation error:
syntax error line 3 at position 52 unexpected '<EOF>'.

I've looked up this error code and tried removing any special characters that might be there, but no luck.

Thanks in advance

3
  • 2
    you are missing one right parenthesis ) Commented Feb 8, 2022 at 20:56
  • 1
    You don't need the first ( in (cast(CODE as string) Commented Feb 8, 2022 at 20:57
  • Wow I feel stupid. Thank you Commented Feb 8, 2022 at 21:06

1 Answer 1

1

If we re-format the SQL:

select 
    NUMBER, 
    ID, 
    DATE, 
    CODE 
from DATABASE.SCHEMA.TABLE
where (
    cast(CODE as string) like 'ABC12%'
    and (
        DATE < '2021-12-31' and DATE >= '2021-10-01'
        )

we can see you are missing the close bracket/paren to the WHERE clause.

But you don't actually need any brackets on this:

select 
    NUMBER, 
    ID, 
    DATE, 
    CODE 
from DATABASE.SCHEMA.TABLE
where CODE::text like 'ABC12%'
    and DATE < '2021-12-31' and DATE >= '2021-10-01'
Sign up to request clarification or add additional context in comments.

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.