简体   繁体   中英

How to retrieve all the table names from a DB schema in snowflake

I am trying to retrieve all the names of the tables in a DB in a particular schema but this is working only on information schema and returning null for others. Here is my attempt:

CREATE PROCEDURE tablename(DB VARCHAR,SC VARCHAR)
RETURNS array
LANGUAGE JAVASCRIPT
AS
$$
    var t = [];
    var stmt = snowflake.createStatement({
    sqlText: "SELECT table_name FROM "+ DB +".information_schema.TABLES where TABLE_TYPE='BASE_TABLE';"});
    var e = stmt.execute();
    
    while(e.next())
    {
       var x = r.getColumnValue('table_name');
       t.push(x);
    }
return t;
$$;

information_schema.TABLES only displays objects for which the current role for the session has been granted access privileges.

Maybe you are missing some privileges and that's why you don't see your other tables but only the tables from information_schema?

To check that you can use SHOW GRANTS.

More infos: https://docs.snowflake.com/en/sql-reference/info-schema/tables.html and https://docs.snowflake.com/en/sql-reference/sql/show-grants.html

Kind regards :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM