为什么greenplum不能在不同的模式中创建相同的表名

时间:2016-07-22 08:20:35

标签: sql ddl greenplum

我希望在不同的模式中在greenplum中创建相同的外部表,但结果是ERROR:relation" my_external_table_name"已存在

click check the picture: this is before create external table

click check the picture: this is after create table

为什么我上一张桌子消失了?

2 个答案:

答案 0 :(得分:2)

首先创建架构

 gpadmin=# create schema foo;
 gpadmin=# create schema bar;

然后在模式中创建外部表

 gpadmin=# CREATE EXTERNAL TABLE foo.fre2(
 ngram text,
 year int4,
 match_count int4,
 page_count int4,
 volume_count int4)
 LOCATION ('gpfdist://mdw:8080/dat.txt')
 FORMAT 'TEXT' (DELIMITER E'\t')
 LOG ERRORS INTO load_e_fre2 SEGMENT REJECT LIMIT 500 rows;

 gpadmin=# CREATE EXTERNAL TABLE bar.fre2(
 ngram text,
 year int4,
 match_count int4,
 page_count int4,
 volume_count int4)
 LOCATION ('gpfdist://mdw:8080/dat.txt')
 FORMAT 'TEXT' (DELIMITER E'\t')
 LOG ERRORS INTO load_e_fre2 SEGMENT REJECT LIMIT 500 rows;

您应该能够在各自的命名空间中看到表格

gpadmin=# select c.relnamespace, c.relname, e.* from pg_class c join pg_exttable e on e.reloid = c.oid where c.relname = 'fre2';
 relnamespace | relname | reloid |           location           | fmttype |                fmtopts                 | command | rejectlimit | rejectlimittype | fmterrtbl | encoding | writable
--------------+---------+--------+------------------------------+---------+----------------------------------------+---------+-------------+-----------------+-----------+----------+----------
2200 | fre2    |  57474 | {gpfdist://mdw:8080/dat.txt} | t       | delimiter '     ' null '\N' escape '\' |         |         500 | r               |     49164 |        6 | f
57403 | fre2    |  57500 | {gpfdist://mdw:8080/dat.txt} | t       | delimiter '     ' null '\N' escape '\' |         |         500 | r               |     49164 |        6 | f
57404 | fre2    |  57526 | {gpfdist://mdw:8080/dat.txt} | t       | delimiter '     ' null '\N' escape '\' |         |         500 | r               |     49164 |        6 | f
(3 rows)


gpadmin=# select nspname from pg_namespace where oid in (2200, 57403, 57404);
 nspname
---------
 public
 foo
 bar
(3 rows)

答案 1 :(得分:0)

以下消息不是前缀"注意"它只是通知用户CREATE语句中定义的错误表不存在,因此它正在为您创建该表。

Notice: Error table "request_histories_external_error" does not exist. Autogenerating and error table with the same name