Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
5bcf8ede
Commit
5bcf8ede
authored
Dec 09, 2011
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ALTER FOREIGN DATA WRAPPER / RENAME and ALTER SERVER / RENAME
parent
9f0d2bdc
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
183 additions
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
No files found.
doc/src/sgml/ref/alter_foreign_data_wrapper.sgml
View file @
5bcf8ede
...
...
@@ -26,6 +26,7 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
[ VALIDATOR <replaceable class="parameter">validator_function</replaceable> | NO VALIDATOR ]
[ 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> RENAME TO <replaceable>new_name</replaceable>
</synopsis>
</refsynopsisdiv>
...
...
@@ -122,6 +123,24 @@ ALTER FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable> OWN
</para>
</listitem>
</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>
</refsect1>
...
...
@@ -150,7 +169,8 @@ ALTER FOREIGN DATA WRAPPER dbi VALIDATOR bob.myvalidator;
<para>
<command>ALTER FOREIGN DATA WRAPPER</command> conforms to ISO/IEC
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>
</refsect1>
...
...
doc/src/sgml/ref/alter_server.sgml
View file @
5bcf8ede
...
...
@@ -24,6 +24,7 @@ PostgreSQL documentation
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>'] [, ... ] ) ]
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>
</refsynopsisdiv>
...
...
@@ -82,6 +83,24 @@ ALTER SERVER <replaceable class="PARAMETER">server_name</replaceable> OWNER TO <
</para>
</listitem>
</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>
</refsect1>
...
...
@@ -108,6 +127,8 @@ ALTER SERVER foo VERSION '8.4' OPTIONS (SET host 'baz');
<para>
<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>
</refsect1>
...
...
src/backend/commands/alter.c
View file @
5bcf8ede
...
...
@@ -65,6 +65,14 @@ ExecRenameStmt(RenameStmt *stmt)
RenameDatabase
(
stmt
->
subname
,
stmt
->
newname
);
break
;
case
OBJECT_FDW
:
RenameForeignDataWrapper
(
stmt
->
subname
,
stmt
->
newname
);
break
;
case
OBJECT_FOREIGN_SERVER
:
RenameForeignServer
(
stmt
->
subname
,
stmt
->
newname
);
break
;
case
OBJECT_FUNCTION
:
RenameFunction
(
stmt
->
object
,
stmt
->
objarg
,
stmt
->
newname
);
break
;
...
...
src/backend/commands/foreigncmds.c
View file @
5bcf8ede
...
...
@@ -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.
*
...
...
src/backend/parser/gram.y
View file @
5bcf8ede
...
...
@@ -6434,6 +6434,14 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
n->newname = $6;
$$ = (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
{
RenameStmt *n = makeNode(RenameStmt);
...
...
@@ -6485,6 +6493,14 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
n->newname = $6;
$$ = (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
{
RenameStmt *n = makeNode(RenameStmt);
...
...
src/include/commands/defrem.h
View file @
5bcf8ede
...
...
@@ -146,6 +146,8 @@ extern text *serialize_deflist(List *deflist);
extern
List
*
deserialize_deflist
(
Datum
txt
);
/* 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
AlterForeignDataWrapperOwner
(
const
char
*
name
,
Oid
newOwnerId
);
extern
void
CreateForeignDataWrapper
(
CreateFdwStmt
*
stmt
);
...
...
src/test/regress/expected/foreign_data.out
View file @
5bcf8ede
...
...
@@ -177,6 +177,17 @@ RESET ROLE;
postgresql | foreign_data_user | - | postgresql_fdw_validator | | |
(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 nonexistent; -- ERROR
ERROR: foreign-data wrapper "nonexistent" does not exist
...
...
@@ -427,6 +438,26 @@ privileges for foreign-data wrapper foo
t2 | regress_test_role | foo | | | | |
(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 nonexistent; -- ERROR
ERROR: server "nonexistent" does not exist
...
...
src/test/regress/sql/foreign_data.sql
View file @
5bcf8ede
...
...
@@ -84,6 +84,10 @@ ALTER FOREIGN DATA WRAPPER foo OPTIONS (ADD e '6'); -- ERROR
RESET
ROLE
;
\
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
nonexistent
;
-- ERROR
DROP
FOREIGN
DATA
WRAPPER
IF
EXISTS
nonexistent
;
...
...
@@ -181,6 +185,10 @@ RESET ROLE;
DROP
ROLE
regress_test_indirect
;
-- ERROR
\
des
+
ALTER
SERVER
s8
RENAME
to
s8new
;
\
des
+
ALTER
SERVER
s8new
RENAME
to
s8
;
-- DROP SERVER
DROP
SERVER
nonexistent
;
-- ERROR
DROP
SERVER
IF
EXISTS
nonexistent
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment