我可以在 Snowflake 中运行此查询,没有任何问题:
select TABLE_NAME
from information_schema.tables
where table_catalog = 'DB' and table_schema = 'SCHEMA';
但是当使用 C# 通过 Visual Studio 运行相同的查询时,读者似乎是空的:
string Query = "select TABLE_NAME from information_schema.tables where table_catalog = 'DB' and table_schema = 'SCHEMA';";
IDbCommand Cmd = Conn.CreateCommand();
Cmd.CommandText = Query;
IDataReader Reader = Cmd.ExecuteReader();
while (Reader.Read())
{
Console.WriteLine("test"); // this never gets printed!
}
但是,我可以从常规表的查询中读取数据,例如
SELECT * FROM TABLE;
有没有办法在 Visual Studio 中读取
information_schema
?或者获取 Snowflake 数据库/模式中所有表的列表的替代方法?
此查询应返回您需要的表信息
information_schema
:
select table_schema, table_name
from information_schema.tables
where table_type = 'BASE TABLE'
您没有说明您正在使用哪个 Snowflake 驱动程序。 SQL 应该是独立的,但执行查询的方式可能有所不同,或者某些驱动程序可能提供内置帮助。
(警告:我在使用
Snowflake.Data
库时遇到了几个问题。)