简体   繁体   English

如何将从 PG_TABLE_DEF 中提取的 data.tablenames 存储到表/临时表中

[英]How to store data(tablenames) extracted from PG_TABLE_DEF into a table/temp table

I will give you the context behind this request.我会告诉你这个请求背后的背景。 This is related to this post Redshift cursor doesn't exist after creating a stored procedure .这与创建存储过程后 Redshift cursor 不存在相关。 I have a workaround for this by using for loop with row_num window function. In order to do that I need to get the list of table names from PG_TABLE_DEF and store it in a temp table for processing through LOOP within Stored Proc.我通过将for 循环row_num window function 一起使用来解决此问题。为此,我需要从PG_TABLE_DEF获取表名列表并将其存储在临时表中,以便通过 Stored Proc 中的 LOOP 进行处理。 The challenge is we cannot run certain operations against table like PG_TABLE_DEF where it runs only on LEADER node.挑战是我们不能对表运行某些操作,比如 PG_TABLE_DEF,它只在 LEADER 节点上运行。 Hence I am getting this below error when i tried to copy data from PG_TABLE_DEF into a new temp table through CTAS .因此,当我尝试通过CTAS将数据从PG_TABLE_DEF复制到新的临时表时,出现以下错误。

ERROR: Specified types or functions (one per INFO message) not supported on Redshift tables.错误:Redshift 表不支持指定的类型或函数(每个 INFO 消息一个)。

Could someone please help to overcome this scenario.有人可以帮助克服这种情况。

As you state pg_table_def only exists on the leader node and on Redshift there is no way for a compute node to access this information during a query.由于您 state pg_table_def 仅存在于领导节点上,而在 Redshift 上,计算节点无法在查询期间访问此信息。 So if you need this information on the compute nodes you need to first query it from the leader and then (somehow) route it back to the compute nodes.因此,如果您需要有关计算节点的此信息,您需要首先从领导者那里查询它,然后(以某种方式)将其路由回计算节点。 This can be done in several ways but all require that you fully execute the query on the leader node first.这可以通过多种方式完成,但都需要您首先在领导节点上完全执行查询。

You can do this with a Lambda function or other externally executed code that reads pg_table_def and then inserts (copys) the data into a normal table.您可以使用 Lambda function 或其他读取 pg_table_def 然后将数据插入(复制)到普通表中的外部执行代码来执行此操作。 OR you can execute the leader node query into a cursor and then read the cursor with a stored procedure depositing the data into a normal table.或者,您可以对 cursor 执行领导节点查询,然后使用存储过程读取 cursor,将数据存入普通表。 These 2 paths do basically the same thing, read the catalog table on the leader node and then put the result of this query into a normal table.这 2 条路径做的事情基本相同,读取领导节点上的目录表,然后将此查询的结果放入普通表中。 I know of no other way to do this.我不知道有其他方法可以做到这一点。

Here's an answer with code for doing this that I wrote up 2 years ago: How to join System tables or Information Schema tables with User defined tables in Redshift这是我 2 年前写的用于执行此操作的代码的答案: How to join System tables or Information Schema tables with User defined tables in Redshift

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

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