Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
5bcf8ede
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5bcf8ede
编写于
12月 09, 2011
作者:
P
Peter Eisentraut
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add ALTER FOREIGN DATA WRAPPER / RENAME and ALTER SERVER / RENAME
上级
9f0d2bdc
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
183 addition
and
1 deletion
+183
-1
doc/src/sgml/ref/alter_foreign_data_wrapper.sgml
doc/src/sgml/ref/alter_foreign_data_wrapper.sgml
+21
-1
doc/src/sgml/ref/alter_server.sgml
doc/src/sgml/ref/alter_server.sgml
+21
-0
src/backend/commands/alter.c
src/backend/commands/alter.c
+8
-0
src/backend/commands/foreigncmds.c
src/backend/commands/foreigncmds.c
+76
-0
src/backend/parser/gram.y
src/backend/parser/gram.y
+16
-0
src/include/commands/defrem.h
src/include/commands/defrem.h
+2
-0
src/test/regress/expected/foreign_data.out
src/test/regress/expected/foreign_data.out
+31
-0
src/test/regress/sql/foreign_data.sql
src/test/regress/sql/foreign_data.sql
+8
-0
未找到文件。
doc/src/sgml/ref/alter_foreign_data_wrapper.sgml
浏览文件 @
5bcf8ede
...
@@ -26,6 +26,7 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
...
@@ -26,6 +26,7 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
[ VALIDATOR <replaceable class="parameter">validator_function</replaceable> | NO VALIDATOR ]
[ VALIDATOR <replaceable class="parameter">validator_function</replaceable> | NO VALIDATOR ]
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ]) ]
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ]) ]
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
</synopsis>
</synopsis>
</refsynopsisdiv>
</refsynopsisdiv>
...
@@ -122,6 +123,24 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWN
...
@@ -122,6 +123,24 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWN
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">new_owner</replaceable></term>
<listitem>
<para>
The user name of the new owner of the foreign-data wrapper.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">new_name</replaceable></term>
<listitem>
<para>
The new name for the foreign-data wrapper.
</para>
</listitem>
</varlistentry>
</variablelist>
</variablelist>
</refsect1>
</refsect1>
...
@@ -150,7 +169,8 @@ ALTER FOREIGN DATA WRAPPER dbi VALIDATOR bob.myvalidator;
...
@@ -150,7 +169,8 @@ ALTER FOREIGN DATA WRAPPER dbi VALIDATOR bob.myvalidator;
<para>
<para>
<command>ALTER FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
<command>ALTER FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
9075-9 (SQL/MED), except that the <literal>HANDLER</literal>,
9075-9 (SQL/MED), except that the <literal>HANDLER</literal>,
<literal>VALIDATOR</> and <literal>OWNER TO</> clauses are extensions.
<literal>VALIDATOR</>, <literal>OWNER TO</>, and <literal>RENAME</literal>
clauses are extensions.
</para>
</para>
</refsect1>
</refsect1>
...
...
doc/src/sgml/ref/alter_server.sgml
浏览文件 @
5bcf8ede
...
@@ -24,6 +24,7 @@ PostgreSQL documentation
...
@@ -24,6 +24,7 @@ PostgreSQL documentation
ALTER SERVER <replaceable class="parameter">server_name</replaceable> [ VERSION '<replaceable class="parameter">new_version</replaceable>' ]
ALTER SERVER <replaceable class="parameter">server_name</replaceable> [ VERSION '<replaceable class="parameter">new_version</replaceable>' ]
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] ) ]
[ OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] ) ]
ALTER SERVER <replaceable class="PARAMETER">server_name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
ALTER SERVER <replaceable class="PARAMETER">server_name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
ALTER SERVER <replaceable class="PARAMETER">server_name</replaceable> RENAME TO <replaceable>new_name</replaceable>
</synopsis>
</synopsis>
</refsynopsisdiv>
</refsynopsisdiv>
...
@@ -82,6 +83,24 @@ ALTER SERVER <replaceable class="PARAMETER">server_name</replaceable> OWNER TO <
...
@@ -82,6 +83,24 @@ ALTER SERVER <replaceable class="PARAMETER">server_name</replaceable> OWNER TO <
</para>
</para>
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">new_owner</replaceable></term>
<listitem>
<para>
The user name of the new owner of the foreign server.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">new_name</replaceable></term>
<listitem>
<para>
The new name for the foreign server.
</para>
</listitem>
</varlistentry>
</variablelist>
</variablelist>
</refsect1>
</refsect1>
...
@@ -108,6 +127,8 @@ ALTER SERVER foo VERSION '8.4' OPTIONS (SET host 'baz');
...
@@ -108,6 +127,8 @@ ALTER SERVER foo VERSION '8.4' OPTIONS (SET host 'baz');
<para>
<para>
<command>ALTER SERVER</command> conforms to ISO/IEC 9075-9 (SQL/MED).
<command>ALTER SERVER</command> conforms to ISO/IEC 9075-9 (SQL/MED).
The <literal>OWNER TO</literal> and <literal>RENAME</literal> forms are
PostgreSQL extensions.
</para>
</para>
</refsect1>
</refsect1>
...
...
src/backend/commands/alter.c
浏览文件 @
5bcf8ede
...
@@ -65,6 +65,14 @@ ExecRenameStmt(RenameStmt *stmt)
...
@@ -65,6 +65,14 @@ ExecRenameStmt(RenameStmt *stmt)
RenameDatabase
(
stmt
->
subname
,
stmt
->
newname
);
RenameDatabase
(
stmt
->
subname
,
stmt
->
newname
);
break
;
break
;
case
OBJECT_FDW
:
RenameForeignDataWrapper
(
stmt
->
subname
,
stmt
->
newname
);
break
;
case
OBJECT_FOREIGN_SERVER
:
RenameForeignServer
(
stmt
->
subname
,
stmt
->
newname
);
break
;
case
OBJECT_FUNCTION
:
case
OBJECT_FUNCTION
:
RenameFunction
(
stmt
->
object
,
stmt
->
objarg
,
stmt
->
newname
);
RenameFunction
(
stmt
->
object
,
stmt
->
objarg
,
stmt
->
newname
);
break
;
break
;
...
...
src/backend/commands/foreigncmds.c
浏览文件 @
5bcf8ede
...
@@ -200,6 +200,82 @@ GetUserOidFromMapping(const char *username, bool missing_ok)
...
@@ -200,6 +200,82 @@ GetUserOidFromMapping(const char *username, bool missing_ok)
}
}
/*
* Rename foreign-data wrapper
*/
void
RenameForeignDataWrapper
(
const
char
*
oldname
,
const
char
*
newname
)
{
HeapTuple
tup
;
Relation
rel
;
rel
=
heap_open
(
ForeignDataWrapperRelationId
,
RowExclusiveLock
);
tup
=
SearchSysCacheCopy1
(
FOREIGNDATAWRAPPERNAME
,
CStringGetDatum
(
oldname
));
if
(
!
HeapTupleIsValid
(
tup
))
ereport
(
ERROR
,
(
errcode
(
ERRCODE_UNDEFINED_OBJECT
),
errmsg
(
"foreign-data wrapper
\"
%s
\"
does not exist"
,
oldname
)));
/* make sure the new name doesn't exist */
if
(
SearchSysCacheExists1
(
FOREIGNDATAWRAPPERNAME
,
CStringGetDatum
(
newname
)))
ereport
(
ERROR
,
(
errcode
(
ERRCODE_DUPLICATE_OBJECT
),
errmsg
(
"foreign-data wrapper
\"
%s
\"
already exists"
,
newname
)));
/* must be owner of FDW */
if
(
!
pg_foreign_data_wrapper_ownercheck
(
HeapTupleGetOid
(
tup
),
GetUserId
()))
aclcheck_error
(
ACLCHECK_NOT_OWNER
,
ACL_KIND_FDW
,
oldname
);
/* rename */
namestrcpy
(
&
(((
Form_pg_foreign_data_wrapper
)
GETSTRUCT
(
tup
))
->
fdwname
),
newname
);
simple_heap_update
(
rel
,
&
tup
->
t_self
,
tup
);
CatalogUpdateIndexes
(
rel
,
tup
);
heap_close
(
rel
,
NoLock
);
heap_freetuple
(
tup
);
}
/*
* Rename foreign server
*/
void
RenameForeignServer
(
const
char
*
oldname
,
const
char
*
newname
)
{
HeapTuple
tup
;
Relation
rel
;
rel
=
heap_open
(
ForeignServerRelationId
,
RowExclusiveLock
);
tup
=
SearchSysCacheCopy1
(
FOREIGNSERVERNAME
,
CStringGetDatum
(
oldname
));
if
(
!
HeapTupleIsValid
(
tup
))
ereport
(
ERROR
,
(
errcode
(
ERRCODE_UNDEFINED_OBJECT
),
errmsg
(
"server
\"
%s
\"
does not exist"
,
oldname
)));
/* make sure the new name doesn't exist */
if
(
SearchSysCacheExists1
(
FOREIGNSERVERNAME
,
CStringGetDatum
(
newname
)))
ereport
(
ERROR
,
(
errcode
(
ERRCODE_DUPLICATE_OBJECT
),
errmsg
(
"server
\"
%s
\"
already exists"
,
newname
)));
/* must be owner of server */
if
(
!
pg_foreign_server_ownercheck
(
HeapTupleGetOid
(
tup
),
GetUserId
()))
aclcheck_error
(
ACLCHECK_NOT_OWNER
,
ACL_KIND_FOREIGN_SERVER
,
oldname
);
/* rename */
namestrcpy
(
&
(((
Form_pg_foreign_server
)
GETSTRUCT
(
tup
))
->
srvname
),
newname
);
simple_heap_update
(
rel
,
&
tup
->
t_self
,
tup
);
CatalogUpdateIndexes
(
rel
,
tup
);
heap_close
(
rel
,
NoLock
);
heap_freetuple
(
tup
);
}
/*
/*
* Change foreign-data wrapper owner.
* Change foreign-data wrapper owner.
*
*
...
...
src/backend/parser/gram.y
浏览文件 @
5bcf8ede
...
@@ -6434,6 +6434,14 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
...
@@ -6434,6 +6434,14 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
n->newname = $6;
n->newname = $6;
$$ = (Node *)n;
$$ = (Node *)n;
}
}
| ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
{
RenameStmt *n = makeNode(RenameStmt);
n->renameType = OBJECT_FDW;
n->subname = $5;
n->newname = $8;
$$ = (Node *)n;
}
| ALTER FUNCTION function_with_argtypes RENAME TO name
| ALTER FUNCTION function_with_argtypes RENAME TO name
{
{
RenameStmt *n = makeNode(RenameStmt);
RenameStmt *n = makeNode(RenameStmt);
...
@@ -6485,6 +6493,14 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
...
@@ -6485,6 +6493,14 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
n->newname = $6;
n->newname = $6;
$$ = (Node *)n;
$$ = (Node *)n;
}
}
| ALTER SERVER name RENAME TO name
{
RenameStmt *n = makeNode(RenameStmt);
n->renameType = OBJECT_FOREIGN_SERVER;
n->subname = $3;
n->newname = $6;
$$ = (Node *)n;
}
| ALTER TABLE relation_expr RENAME TO name
| ALTER TABLE relation_expr RENAME TO name
{
{
RenameStmt *n = makeNode(RenameStmt);
RenameStmt *n = makeNode(RenameStmt);
...
...
src/include/commands/defrem.h
浏览文件 @
5bcf8ede
...
@@ -146,6 +146,8 @@ extern text *serialize_deflist(List *deflist);
...
@@ -146,6 +146,8 @@ extern text *serialize_deflist(List *deflist);
extern
List
*
deserialize_deflist
(
Datum
txt
);
extern
List
*
deserialize_deflist
(
Datum
txt
);
/* commands/foreigncmds.c */
/* commands/foreigncmds.c */
extern
void
RenameForeignServer
(
const
char
*
oldname
,
const
char
*
newname
);
extern
void
RenameForeignDataWrapper
(
const
char
*
oldname
,
const
char
*
newname
);
extern
void
AlterForeignServerOwner
(
const
char
*
name
,
Oid
newOwnerId
);
extern
void
AlterForeignServerOwner
(
const
char
*
name
,
Oid
newOwnerId
);
extern
void
AlterForeignDataWrapperOwner
(
const
char
*
name
,
Oid
newOwnerId
);
extern
void
AlterForeignDataWrapperOwner
(
const
char
*
name
,
Oid
newOwnerId
);
extern
void
CreateForeignDataWrapper
(
CreateFdwStmt
*
stmt
);
extern
void
CreateForeignDataWrapper
(
CreateFdwStmt
*
stmt
);
...
...
src/test/regress/expected/foreign_data.out
浏览文件 @
5bcf8ede
...
@@ -177,6 +177,17 @@ RESET ROLE;
...
@@ -177,6 +177,17 @@ RESET ROLE;
postgresql | foreign_data_user | - | postgresql_fdw_validator | | |
postgresql | foreign_data_user | - | postgresql_fdw_validator | | |
(3 rows)
(3 rows)
ALTER FOREIGN DATA WRAPPER foo RENAME TO foo1;
\dew+
List of foreign-data wrappers
Name | Owner | Handler | Validator | Access privileges | FDW Options | Description
------------+-------------------------+---------+--------------------------+-------------------+------------------------------+-------------
dummy | foreign_data_user | - | - | | | useless
foo1 | regress_test_role_super | - | - | | (b '3', c '4', a '2', d '5') |
postgresql | foreign_data_user | - | postgresql_fdw_validator | | |
(3 rows)
ALTER FOREIGN DATA WRAPPER foo1 RENAME TO foo;
-- DROP FOREIGN DATA WRAPPER
-- DROP FOREIGN DATA WRAPPER
DROP FOREIGN DATA WRAPPER nonexistent; -- ERROR
DROP FOREIGN DATA WRAPPER nonexistent; -- ERROR
ERROR: foreign-data wrapper "nonexistent" does not exist
ERROR: foreign-data wrapper "nonexistent" does not exist
...
@@ -427,6 +438,26 @@ privileges for foreign-data wrapper foo
...
@@ -427,6 +438,26 @@ privileges for foreign-data wrapper foo
t2 | regress_test_role | foo | | | | |
t2 | regress_test_role | foo | | | | |
(10 rows)
(10 rows)
ALTER SERVER s8 RENAME to s8new;
\des+
List of foreign servers
Name | Owner | Foreign-data wrapper | Access privileges | Type | Version | FDW Options | Description
-------+-----------------------+----------------------+-----------------------------------------+--------+---------+--------------------------------------+-------------
s1 | regress_test_indirect | foo | foreign_data_user=U/foreign_data_user +| | 1.1 | (servername 's1') |
| | | regress_test_role=U/foreign_data_user | | | |
s2 | foreign_data_user | foo | | | 1.1 | (host 'a', dbname 'b') |
s3 | foreign_data_user | foo | | oracle | | ("tns name" 'orcl', port '1521') |
s4 | foreign_data_user | foo | | oracle | | (host 'a', dbname 'b') |
s5 | foreign_data_user | foo | | | 15.0 | |
s6 | foreign_data_user | foo | foreign_data_user=U/foreign_data_user +| | 16.0 | (host 'a', dbname 'b') |
| | | regress_test_role2=U*/foreign_data_user | | | |
s7 | foreign_data_user | foo | | oracle | 17.0 | (host 'a', dbname 'b') |
s8new | foreign_data_user | postgresql | | | | (dbname 'db1', connect_timeout '30') |
t1 | regress_test_role | foo | | | | |
t2 | regress_test_role | foo | | | | |
(10 rows)
ALTER SERVER s8new RENAME to s8;
-- DROP SERVER
-- DROP SERVER
DROP SERVER nonexistent; -- ERROR
DROP SERVER nonexistent; -- ERROR
ERROR: server "nonexistent" does not exist
ERROR: server "nonexistent" does not exist
...
...
src/test/regress/sql/foreign_data.sql
浏览文件 @
5bcf8ede
...
@@ -84,6 +84,10 @@ ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD e '6'); -- ERROR
...
@@ -84,6 +84,10 @@ ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD e '6'); -- ERROR
RESET
ROLE
;
RESET
ROLE
;
\
dew
+
\
dew
+
ALTER
FOREIGN
DATA
WRAPPER
foo
RENAME
TO
foo1
;
\
dew
+
ALTER
FOREIGN
DATA
WRAPPER
foo1
RENAME
TO
foo
;
-- DROP FOREIGN DATA WRAPPER
-- DROP FOREIGN DATA WRAPPER
DROP
FOREIGN
DATA
WRAPPER
nonexistent
;
-- ERROR
DROP
FOREIGN
DATA
WRAPPER
nonexistent
;
-- ERROR
DROP
FOREIGN
DATA
WRAPPER
IF
EXISTS
nonexistent
;
DROP
FOREIGN
DATA
WRAPPER
IF
EXISTS
nonexistent
;
...
@@ -181,6 +185,10 @@ RESET ROLE;
...
@@ -181,6 +185,10 @@ RESET ROLE;
DROP
ROLE
regress_test_indirect
;
-- ERROR
DROP
ROLE
regress_test_indirect
;
-- ERROR
\
des
+
\
des
+
ALTER
SERVER
s8
RENAME
to
s8new
;
\
des
+
ALTER
SERVER
s8new
RENAME
to
s8
;
-- DROP SERVER
-- DROP SERVER
DROP
SERVER
nonexistent
;
-- ERROR
DROP
SERVER
nonexistent
;
-- ERROR
DROP
SERVER
IF
EXISTS
nonexistent
;
DROP
SERVER
IF
EXISTS
nonexistent
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录