简体   繁体   English

如何查询 Redshift 以获取特定数据库的所有模式名称

[英]How to query Redshift to obtain all the schema names for a specific database

I understand that a database lives inside a schema, but I'm working with an existing design.我知道数据库存在于模式中,但我正在使用现有设计。 My old query which targeted postgres is below.我的针对 postgres 的旧查询如下。 I want to recreate it for Redshift.我想为 Redshift 重新创建它。 Or some help linking a database to a schema.或者一些帮助将数据库链接到模式。

select
d.datname database_name
,s.schema_name
from pg_catalog.pg_database d
inner join information_schema.schemata s on s.catalog_name = d.datname
where d.datname = @database_name

So for some reason the "public" schemas are not included in the information_schema.schemata.所以由于某种原因,“公共”模式不包含在 information_schema.schema 中。

My current work-around is:我目前的解决方法是:

select cast(@database_name as char(150)) database_name,cast('public' as char(150)) schema_name
union all
select
cast(d.datname as char(150))  database_name
,cast(s.schema_name as char(150)) schema_name
from pg_catalog.pg_database d
inner join information_schema.schemata s on s.catalog_name = d.datname
where d.datname = @database_name

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL查询以获取特定模式名称下的所有标题名称 - SQL query to get all the heading names under a specific schema name 如何检索数据库(如 snowflake 或任何此类数据库)中的所有目录名称、模式名称和表名称? - How to retrieve all the catalog names , schema names and the table names in a database like snowflake or any such database? 创建 SQL 查询以查找整个 Redshift 数据库中包含特定文本字符串(数据)的所有表 - Create an SQL query to find all tables in the whole Redshift database containing a specific text string (data) 如何在 Redshift 中的同一数据库上创建完整模式的副本 - How to create copy of full schema on same database in Redshift 如何在数据库 Teradata 中查找具有特定列名的所有表? - How to find all the tables in database Teradata with specific column names in them? 本机SQL-如何设置架构和数据库名称 - Native SQL - How to set the schema and database names SQL:用于查询特定值和返回表名称的整个架构 - SQL: Query Entire Schema for Specific Value and Return Table Names 获取特定数据库的 SQL Server 执行查询历史记录 - Obtain SQL Server executed query history of specific database 用于检索给定模式的所有表名的 DB2 查询 - DB2 Query to retrieve all table names for a given schema 查询以在 IMPALA 中一起显示所有列、表和模式名称 - Query to show all column, table and schema names together in IMPALA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM