1

我正在尝试进行类似于以下的查询:

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)

我的查询看起来像这样:

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')

我收到此错误:

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

我查看了此错误代码并尝试删除可能存在的任何特殊字符,但没有运气。

提前致谢

4

1 回答 1

1

如果我们重新格式化 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'
        )

我们可以看到您缺少 WHERE 子句的右括号/括号。

但是您实际上不需要任何括号:

select 
    NUMBER, 
    ID, 
    DATE, 
    CODE 
from DATABASE.SCHEMA.TABLE
where CODE::text like 'ABC12%'
    and DATE < '2021-12-31' and DATE >= '2021-10-01'
于 2022-02-08T21:08:00.873 回答