雪花查询适用于 cli 但不适用于 python 雪花连接器

snowflake query works with cli but not python snowflake connector

#!/bin/bash

query="""
select table_name,table_schema
from CDP.information_schema.tables
where table_schema != 'INFORMATION_SCHEMA';
"""

snowsql -c latchsnowflake -d ${dbname} -s ${schema} -r ${role} -w ${warehouse} -q "${query}"

那运行秒。

使用雪花连接器的等效命令-python

使用相同的凭据找不到数据库。当我通过 UI 检查历史记录中的查询时,我可以看到仓库没有被使用。

我这样创建连接和 运行 查询:

#!/usr/bin/env python
conn = snowflake.connector.connect(
                user=self.SNOWFLAKE_USER,
                password=self.SNOWFLAKE_PASSWORD,
                account=self.SNOWFLAKE_ACCOUNT,
                warehouse=self.SNOWFLAKE_WAREHOUSE,
                database=self.SNOWFLAKE_DATABASE,
                schema=self.SNOWFLAKE_SCHEMA,
                )        
query = """
    select table_name,table_schema
    from CDP.information_schema.tables
    where table_schema != 'INFORMATION_SCHEMA';
    """
cur = conn.cursor()
cur.execute(query)
print(cur.fetchall())
cur.close()

然而,错误如下:

snowflake.connector.errors.ProgrammingError: 002003 (02000): SQL compilation error:
Database 'CDP' does not exist or not authorized.

在您的 SnowSQL 版本中,您正在指定一个角色。但是,在您的 python 中,您不是。确保用户的默认角色与您在 SnowSQL 连接中使用的角色相同。