提交 d244a783 编写于 作者: H Heikki Linnakangas

Fix ALTER EXTERNAL TABLE ... ALTER TYPE to not require USING.

Don't require a USING clause, when there is no cast between the old and
new datatype are not compatible, when altering an external table. It'll
just be ignored, we're not going to rewrite any data in an external
source. And conversely, don't allow USING, because it'll just be ignored.

Fixes https://github.com/greenplum-db/gpdb/issues/3356
上级 0032f133
......@@ -11,7 +11,7 @@
<p>where <varname>action</varname> is one of:</p>
<codeblock>  ADD [COLUMN] <varname>new_column</varname> <varname>type</varname>
  DROP [COLUMN] <varname>column</varname> [RESTRICT|CASCADE]
  ALTER [COLUMN] <varname>column</varname> TYPE <varname>type</varname> [USING <varname>expression</varname>]
  ALTER [COLUMN] <varname>column</varname> TYPE <varname>type</varname>
  OWNER TO <varname>new_owner</varname></codeblock>
</sectiondiv></section>
<section id="section3">
......@@ -61,12 +61,6 @@
<pt><varname>new_column</varname></pt>
<pd>Name of a new column.</pd>
</plentry>
<plentry>
<pt>USING <varname>expression</varname></pt>
<pd>Optional if an implicit or assignment cast exists from the old column data type to new
data type. The clause is required if there is no implicit or assignment cast. </pd>
<pd>The <codeph>USING</codeph> clause does not affect the external data.</pd>
</plentry>
<plentry>
<pt><varname>type</varname></pt>
<pd>Data type of the new column, or new data type for an existing column.</pd>
......@@ -90,10 +84,8 @@
definition:</p><codeblock>ALTER EXTERNAL TABLE ext_expenses ADD COLUMN manager text;</codeblock><p>Change
the owner of an external
table:</p><codeblock>ALTER EXTERNAL TABLE ext_data OWNER TO jojo;</codeblock><p>Change the
data type of an external table:</p><codeblock>ALTER EXTERNAL TABLE ext_leads ALTER COLUMN acct_code TYPE integer USING acct_code::integer</codeblock>
<p>When altering the column data type from <codeph>text</codeph> to <codeph>integer</codeph>,
the <codeph>USING</codeph> clause is required but does not affect the external data.
</p></section>
data type of an external table:</p><codeblock>ALTER EXTERNAL TABLE ext_leads ALTER COLUMN acct_code TYPE integer</codeblock>
</section>
<section id="section6"><title>Compatibility</title><p><codeph>ALTER EXTERNAL TABLE</codeph> is a
Greenplum Database extension. There is no <codeph>ALTER EXTERNAL TABLE</codeph> statement in
the SQL standard or regular PostgreSQL. </p></section>
......
......@@ -10477,7 +10477,8 @@ ATPrepAlterColumnType(List **wqueue,
CheckAttributeType(colName, targettype, targetcollid,
list_make1_oid(rel->rd_rel->reltype),
false);
if (tab->relkind == RELKIND_RELATION)
if (tab->relkind == RELKIND_RELATION &&
rel->rd_rel->relstorage != RELSTORAGE_EXTERNAL)
{
/*
* Set up an expression to transform the old data value to the new
......@@ -10562,6 +10563,14 @@ ATPrepAlterColumnType(List **wqueue,
if (ATColumnChangeRequiresRewrite(transform, attnum))
tab->rewrite = true;
}
else if (transform &&
rel->rd_rel->relstorage == RELSTORAGE_EXTERNAL)
{
/* Just to give a better error message than "foo is not a table" */
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("cannot specify a USING expression when altering an external table")));
}
else if (transform)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
......
......@@ -159,6 +159,9 @@ alter external table ext add column extnewcol int not null; -- should fail (cons
alter external table ext add column extnewcol int; -- pass
alter external table ext alter column extnewcol set default 1; -- should fail (unsupported alter type)
alter external table ext alter column x type integer using 123; -- should fail (USING doesn't make sense on external table)
alter external table ext alter column x type integer; -- pass
--
-- TRUNCATE/UPDATE/DELETE/INSERT (INTO RET)
--
......
......@@ -193,6 +193,9 @@ ERROR: Unsupported ALTER command for table type external. No constraints allowe
alter external table ext add column extnewcol int; -- pass
alter external table ext alter column extnewcol set default 1; -- should fail (unsupported alter type)
ERROR: Unsupported ALTER command for table type external
alter external table ext alter column x type integer using 123; -- should fail (USING doesn't make sense on external table)
ERROR: cannot specify a USING expression when altering an external table
alter external table ext alter column x type integer; -- pass
--
-- TRUNCATE/UPDATE/DELETE/INSERT (INTO RET)
--
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册