Amazon redshift 无法使用红移目录查询的输出

Amazon redshift 无法使用红移目录查询的输出,amazon-redshift,Amazon Redshift,我在处理针对红移目录表的查询时遇到各种各样的问题 举例来说,以下工作: select "table_name"::text as "table" from "information_schema"."tables" where table_schema not like 'pg_%' and table_schema != 'information_schema' create view works as select "table_name"::text as "table" from "

我在处理针对红移目录表的查询时遇到各种各样的问题

举例来说,以下工作:

select "table_name"::text as "table"
from "information_schema"."tables"
where table_schema not like 'pg_%' and table_schema != 'information_schema'
create view works as 
select "table_name"::text as "table"
from "information_schema"."tables"
where table_schema not like 'pg_%' and table_schema != 'information_schema'
以及以下工作:

select "table_name"::text as "table"
from "information_schema"."tables"
where table_schema not like 'pg_%' and table_schema != 'information_schema'
create view works as 
select "table_name"::text as "table"
from "information_schema"."tables"
where table_schema not like 'pg_%' and table_schema != 'information_schema'
但以下几点失败了:

create table fails as
select "table_name"::text as "table"
from "information_schema"."tables"
where table_schema not like 'pg_%' and table_schema != 'information_schema'
与:

从我读到的

如果编写的联接查询显式或隐式引用了具有不受支持的数据类型的列,则该查询将返回错误

这是否意味着在基于目录表选择的创建表中,即使我将奇怪的字段类型转换为文本,但在后台红移正在执行连接和奇怪的操作,这意味着我不能这样做

创建表是问题的一种表现形式。另一个原因是,我无法卸载基于目录查询的视图或任何内容。例如,以下操作也将失败,并显示与上述类似的错误消息

unload ('select * from "works"') to 's3://etc'
目前,我处理这些数据的唯一方法似乎是从外部程序发出查询,然后让外部程序手动将结果集写回到表中。i、 e.不能从数据库中执行


有人有其他解决办法吗?

我遇到了类似的问题,我不确定原因的细节,但找到了解决办法

不要在information_schema中查找值,而是尝试在pg_目录表中查找关系和属性名称

例如,以下查询提供特定表的列名:

SELECT attname::text FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = '<your_table_name>') AND attname NOT IN ('insertxid', 'deletexid', 'oid', 'tableoid', 'xmin', 'cmin', 'xmax', 'cmax', 'ctid');
请注意,目录表提供的系统级详细信息比模式提供的信息多得多。例如,每个表都有上面的查询返回的内部系统列,因此如果您只需要DDL中定义的列的列名,则需要排除内部系统列。除了列出的列之外,RedShift还从上面的查询返回deletexid和insertxid,因此也应该排除它们。表列表的查询也是如此,即返回许多系统模式

我怀疑这与列的数据类型有关。在SQLWorkbenchJ中查看时,information_模式中许多列的数据类型为“sql_identifier”,JDBC类型为“OTHER”,而类似列的pg_目录表的数据类型为“name”,JDBC类型为“VARCHAR”

CREATE TABLE tmp_table_names AS
SELECT relname::text, nspname::text
FROM pg_class c
JOIN pg_namespace n
ON n.oid = c.relnamespace
WHERE nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema');