【发布时间】:2021-11-11 09:49:16
【问题描述】:
我正在尝试收集一些有关 ETL 流程的经验,因此我正在寻找将数据从一个地方传输到另一个地方的方法。现在,我想更好地掌握 postgres_fdw 扩展,因为如果我理解正确,它允许我用一个命令导入整个架构。
IMPORT FOREIGN SCHEMA "public"
FROM SERVER dvdrental into "public";
我已经按照整个文档安装和使用 fwd 扩展以及从其他表手动导入工作正常。但是,当我尝试这种“批量导入”时,对于一个特定的表,我收到以下错误:
ERROR: type "public.year" does not exist
LINE 5: release_year public.year OPTIONS (column_name 'release_yea...
^
QUERY: CREATE FOREIGN TABLE film (
film_id integer OPTIONS (column_name 'film_id') NOT NULL,
title character varying(255) OPTIONS (column_name 'title') COLLATE pg_catalog."default" NOT NULL,
description text OPTIONS (column_name 'description') COLLATE pg_catalog."default",
release_year public.year OPTIONS (column_name 'release_year'),
language_id smallint OPTIONS (column_name 'language_id') NOT NULL,
rental_duration smallint OPTIONS (column_name 'rental_duration') NOT NULL,
rental_rate numeric(4,2) OPTIONS (column_name 'rental_rate') NOT NULL,
length smallint OPTIONS (column_name 'length'),
replacement_cost numeric(5,2) OPTIONS (column_name 'replacement_cost') NOT NULL,
rating public.mpaa_rating OPTIONS (column_name 'rating'),
last_update timestamp without time zone OPTIONS (column_name 'last_update') NOT NULL,
special_features text[] OPTIONS (column_name 'special_features') COLLATE pg_catalog."default",
fulltext tsvector OPTIONS (column_name 'fulltext') NOT NULL
) SERVER dvdrental
OPTIONS (schema_name 'public', table_name 'film');
CONTEXT: importing foreign table "film"
SQL state: 42704
当我查看第 5 行时,我明白为什么 postgres 会抛出错误。它试图创建类型为public.year 的列release_year。但是,这不是一个有效的类型(如 INTEGER),因此我得到了错误。
不过,我该如何解决呢?我的意思是,如何覆盖 postgres 尝试为此特定列设置的数据类型?
【问题讨论】:
-
@a_horse_with_no_name 谢谢!那是为我做的。我还必须创建电影表使用的类型 mpaa_rating,但除此之外它工作得很好。我会礼貌地请您写一个更笼统的回复,以便我可以将其标记为答案!