> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/reference/sql-commands/sql-alterforeigndatawrapper.md).

# ALTER FOREIGN DATA WRAPPER

### ALTER FOREIGN DATA WRAPPER

ALTER FOREIGN DATA WRAPPER — change the definition of a foreign-data wrapper

### Synopsis

```

ALTER FOREIGN DATA WRAPPER name
    [ HANDLER handler_function | NO HANDLER ]
    [ VALIDATOR validator_function | NO VALIDATOR ]
    [ OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ]) ]
ALTER FOREIGN DATA WRAPPER name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER FOREIGN DATA WRAPPER name RENAME TO new_name
```

### Description

`ALTER FOREIGN DATA WRAPPER` changes the definition of a foreign-data wrapper. The first form of the command changes the support functions or the generic options of the foreign-data wrapper (at least one clause is required). The second form changes the owner of the foreign-data wrapper.

Only superusers can alter foreign-data wrappers. Additionally, only superusers can own foreign-data wrappers.

### Parameters

*`name`* : The name of an existing foreign-data wrapper.

`HANDLER handler_function` : Specifies a new handler function for the foreign-data wrapper.

`NO HANDLER` : This is used to specify that the foreign-data wrapper should no longer have a handler function.

```
Note that foreign tables that use a foreign-data wrapper with no
handler cannot be accessed.
```

`VALIDATOR validator_function` : Specifies a new validator function for the foreign-data wrapper.

```
Note that it is possible that pre-existing options of the foreign-data
wrapper, or of dependent servers, user mappings, or foreign tables, are
invalid according to the new validator. PostgreSQL does
not check for this. It is up to the user to make sure that these
options are correct before using the modified foreign-data wrapper.
However, any options specified in this `ALTER FOREIGN DATA
WRAPPER` command will be checked using the new validator.
```

`NO VALIDATOR` : This is used to specify that the foreign-data wrapper should no longer have a validator function.

`OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] )` : Change options for the foreign-data wrapper. `ADD`, `SET`, and `DROP` specify the action to be performed. `ADD` is assumed if no operation is explicitly specified. Option names must be unique; names and values are also validated using the foreign data wrapper's validator function, if any.

*`new_owner`* : The user name of the new owner of the foreign-data wrapper.

*`new_name`* : The new name for the foreign-data wrapper.

### Examples

Change a foreign-data wrapper `dbi`, add option `foo`, drop `bar`:

```

ALTER FOREIGN DATA WRAPPER dbi OPTIONS (ADD foo '1', DROP bar);
```

Change the foreign-data wrapper `dbi` validator to `bob.myvalidator`:

```

ALTER FOREIGN DATA WRAPPER dbi VALIDATOR bob.myvalidator;
```

### Compatibility

`ALTER FOREIGN DATA WRAPPER` conforms to ISO/IEC 9075-9 (SQL/MED), except that the `HANDLER`, `VALIDATOR`, `OWNER TO`, and `RENAME` clauses are extensions.

### See Also

[CREATE FOREIGN DATA WRAPPER](/reference/sql-commands/sql-createforeigndatawrapper.md), [DROP FOREIGN DATA WRAPPER](/reference/sql-commands/sql-dropforeigndatawrapper.md)

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/sql-alterforeigndatawrapper.html)（英文原文，待翻譯）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.postgresql.tw/reference/sql-commands/sql-alterforeigndatawrapper.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
