postgresql - postgres_fdw 扩展没有解释正确的数据类型
问题描述
我正在尝试收集一些有关 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 试图为这个特定列设置的数据类型?
解决方案
该表对列film
使用域,对year
列使用枚举rating
。
IMPORT FOREIGN SCHEMA
只导入表和视图,所以它不导入域、枚举和其他东西。
您需要在导入架构之前手动创建它们。
CREATE TYPE public.mpaa_rating AS ENUM (
'G',
'PG',
'PG-13',
'R',
'NC-17'
);
CREATE DOMAIN public.year AS integer
CONSTRAINT year_check CHECK (((VALUE >= 1901) AND (VALUE <= 2155)));
推荐阅读
- laravel - 如何保存多选值?
- c - libelf 例如缺少 vis.h 标头
- java - java 2d 数组上的 java.lang.ArrayIndexOutOfBoundsException
- postgresql - 大 COUNT DISTINCT 在 postgresql 中执行缓慢
- python - 如何在字符串拆分中找到双倍间距?
- mysql - Docker MySQL 没有创建用户
- javascript - JavaScript“document.getElementById().innerHTML”在循环中等待
- wordpress - 无法在谷歌应用引擎上安装 wordpress 插件
- c - 使用非 NULL 指针时出现分段错误
- batch-file - 需要根据笔式驱动器和文件的可用性将文件提取到笔式驱动器中