Skip to main content
Version: 1.0.16

CREATE USER MAPPING

CREATE USER MAPPING — Define a new mapping of a user to a foreign server

Synopsis

CREATE USER MAPPING [IF NOT EXISTS] FOR { user_name | USER | CURRENT_USER | PUBLIC }

SERVER server_name

[ OPTIONS ( option 'value' [ , ... ] ) ]

Description

CREATE USER MAPPING defines a new mapping of a user to a foreign server. A user mapping typically contains connection information that the foreign data wrapper will use together with information from the foreign server to access an external data source.

The owner of a foreign server can create user mappings for any server for any user. Also, if a user has been granted the USAGE privilege on a server, that user can create a user mapping for their own user name.

Parameters

IF NOT EXISTS

Do not throw an error if a mapping for the given user to the given foreign server already exists. A notice is issued in this case. Note that there is no guarantee that the existing user mapping is exactly the same as the one that would be created.

user_name

The name of an existing user to map to the foreign server. CURRENT_USER and USER match the name of the current user. When PUBLIC is specified, a so-called public mapping is created, which will be used when no specific user mapping is available.

server_name

The name of an existing server for which the user mapping is to be created.

OPTIONS ( option 'value' [, ... ] )

This clause specifies the options for the user mapping. These options typically define the actual user name and password for the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign data wrapper.

Examples

# Create a user mapping for user bob, server foo:

CREATE USER MAPPING FOR bob SERVER foo OPTIONS (user 'bob', password 'secret');

See Also

ALTER USER MAPPING, DROP USER MAPPING, CREATE FOREIGN DATA WRAPPER, CREATE SERVER