{"Entry":{"collection":"sql","key":"create-user-mapping","name":"CREATE USER MAPPING","aliases":["createusermapping"],"metadata":{"aliases":["createusermapping"],"changed_in":["9.0","10","14"],"changes":[{"from":"8.3","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"8.4"},{"from":"8.4","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters"],"removed":[]},"status":"changed","synopsis":{"added":["CREATE USER MAPPING FOR { user_name | USER | CURRENT_USER | PUBLIC }","SERVER server_name"],"removed":["CREATE USER MAPPING FOR { username | USER | CURRENT_USER | PUBLIC }","SERVER servername"]},"to":"9.0"},{"from":"9.5","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"9.6"},{"from":"9.6","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters"],"removed":[]},"status":"changed","synopsis":{"added":["CREATE USER MAPPING [IF NOT EXISTS] FOR { user_name | USER | CURRENT_USER | PUBLIC }"],"removed":[]},"to":"10"},{"from":"13","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters"],"removed":[]},"status":"changed","synopsis":{"added":["CREATE USER MAPPING [ IF NOT EXISTS ] FOR { user_name | USER | CURRENT_ROLE | CURRENT_USER | PUBLIC }"],"removed":[]},"to":"14"}],"content_hash":"42e7a4e99635cf7b9484b60c5f0db0d21adbeb7d3e00ee450e01952b1fb6f55b","editorial":{},"first_version":"8.4","group":"foreign","imported_at":"2026-09-30T17:43:38.853472+08:00","last_version":"20","name":"CREATE USER MAPPING","object":"USER MAPPING","position":9010,"present_in":["8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"purpose":"define a new mapping of a user to a foreign server","purpose_zh":"","related":["alter-user-mapping","drop-user-mapping","create-foreign-data-wrapper","create-server"],"slug":"create-user-mapping","source_rev":"a709ab85","synopsis":"CREATE USER MAPPING [ IF NOT EXISTS ] FOR { user_name | USER | CURRENT_ROLE | CURRENT_USER | PUBLIC }\nSERVER server_name\n[ OPTIONS ( option 'value' [ , ... ] ) ]","verb":"CREATE"}},"Definition":{"Collection":"sql","Key":"create-user-mapping","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"create-user-mapping","SourceRevision":"a709ab85","Facts":{"anchor":"SQL-CREATEUSERMAPPING","file":"sql-createusermapping.html","lang":"en","name":"CREATE USER MAPPING","purpose":"define a new mapping of a user to a foreign server","purpose_zh":"","related":["alter-user-mapping","drop-user-mapping","create-foreign-data-wrapper","create-server"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE USER MAPPING\u003c/code\u003e defines a mapping of a user to a foreign server. A user mapping typically encapsulates connection information that a foreign-data wrapper uses together with the information encapsulated by a foreign server to access an external data resource.\u003c/p\u003e\u003cp\u003eThe owner of a foreign server can create user mappings for that server for any user. Also, a user can create a user mapping for their own user name if \u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e privilege on the server has been granted to the user.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eIF NOT EXISTS\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eDo not throw an error if a mapping of 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 anything like the one that would have been created.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003euser_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name of an existing user that is mapped to foreign server. \u003ccode class=\"literal\"\u003eCURRENT_ROLE\u003c/code\u003e, \u003ccode class=\"literal\"\u003eCURRENT_USER\u003c/code\u003e, and \u003ccode class=\"literal\"\u003eUSER\u003c/code\u003e match the name of the current user. When \u003ccode class=\"literal\"\u003ePUBLIC\u003c/code\u003e is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name of an existing server for which the user mapping is to be created.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eOPTIONS ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e '\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e' [, ... ] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThis clause specifies the options of the user mapping. The options typically define the actual user name and password of the mapping. Option names must be unique. The allowed option names and values are specific to the server's foreign-data wrapper.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eCreate a user mapping for user \u003ccode class=\"literal\"\u003ebob\u003c/code\u003e, server \u003ccode class=\"literal\"\u003efoo\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE USER MAPPING FOR bob SERVER foo OPTIONS (user 'bob', password 'secret');\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE USER MAPPING\u003c/code\u003e conforms to ISO/IEC 9075-9 (SQL/MED).\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/alter-user-mapping/?v=18\" title=\"ALTER USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER USER MAPPING\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-user-mapping/?v=18\" title=\"DROP USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP USER MAPPING\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-foreign-data-wrapper/?v=18\" title=\"CREATE FOREIGN DATA WRAPPER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN DATA WRAPPER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-server/?v=18\" title=\"CREATE SERVER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"CREATE USER MAPPING [ IF NOT EXISTS ] FOR { \u003cem class=\"replaceable\"\u003e\u003ccode\u003euser_name\u003c/code\u003e\u003c/em\u003e | USER | CURRENT_ROLE | CURRENT_USER | PUBLIC }\n    SERVER \u003cem class=\"replaceable\"\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\n    [ OPTIONS ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e '\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e' [ , ... ] ) ]","synopsis_text":"CREATE USER MAPPING [ IF NOT EXISTS ] FOR { user_name | USER | CURRENT_ROLE | CURRENT_USER | PUBLIC }\nSERVER server_name\n[ OPTIONS ( option 'value' [ , ... ] ) ]"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"create-user-mapping","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"CREATE USER MAPPING","Summary":"定义用户到外部服务器的新映射","BodyHTML":"\u003cpre\u003eCREATE USER MAPPING [ IF NOT EXISTS ] FOR { user_name | USER | CURRENT_ROLE | CURRENT_USER | PUBLIC }\nSERVER server_name\n[ OPTIONS ( option \u0026#39;value\u0026#39; [ , ... ] ) ]\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eCREATE USER MAPPING\u003c/code\u003e定义用户到外部服务器的映射。用户映射通常封装连接信息，外部数据包装器会将其与外部服务器所封装的信息结合起来，以访问外部数据资源。\u003c/p\u003e\u003cp\u003e外部服务器的拥有者可以创建任意用户到该服务器的用户映射。此外，如果某个用户已被授予该服务器上的\u003ccode\u003eUSAGE\u003c/code\u003e权限，那么该用户也可以为自己的用户名创建用户映射。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\u003c/h2\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eIF NOT EXISTS\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e如果给定用户到给定外部服务器的映射已经存在，则不要报错。这种情况下会发出一个提示。请注意，不能保证现有用户映射与本应创建的映射有任何相似之处。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003euser_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e被映射到外部服务器的现有用户的名称。\u003ccode\u003eCURRENT_ROLE\u003c/code\u003e、\u003ccode\u003eCURRENT_USER\u003c/code\u003e 和\u003ccode\u003eUSER\u003c/code\u003e都匹配当前用户的名称。当指定 \u003ccode\u003ePUBLIC\u003c/code\u003e时，会创建一个所谓的公共映射；当没有适用的特定用户映射时，就会使用它。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e将为其创建用户映射的现有服务器的名称。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eOPTIONS ( \u003cem\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e \u0026#39;\u003cem\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e\u0026#39; [, ... ] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e该子句指定用户映射的选项。这些选项通常定义该映射实际的用户名和密码。选项名必须唯一。允许的选项名和值取决于该服务器的外部数据包装器。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e为用户\u003ccode\u003ebob\u003c/code\u003e、服务器\u003ccode\u003efoo\u003c/code\u003e创建一个用户映射：\u003c/p\u003e\u003cpre\u003eCREATE USER MAPPING FOR bob SERVER foo OPTIONS (user \u0026#39;bob\u0026#39;, password \u0026#39;secret\u0026#39;);\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eCREATE USER MAPPING\u003c/code\u003e符合 ISO/IEC 9075-9（SQL/MED）。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/alter-user-mapping/?v=18\" title=\"ALTER USER MAPPING\" rel=\"nofollow\"\u003e\u003cspan\u003eALTER USER MAPPING\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-user-mapping/?v=18\" title=\"DROP USER MAPPING\" rel=\"nofollow\"\u003e\u003cspan\u003eDROP USER MAPPING\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-foreign-data-wrapper/?v=18\" title=\"CREATE FOREIGN DATA WRAPPER\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE FOREIGN DATA WRAPPER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-server/?v=18\" title=\"CREATE SERVER\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"1b5ca64c","ContentHash":"3395cd8c5236b97e64f6dd5b4d846c6a66140887ae200023ba1b1dd7e19afc0b","Payload":{"purpose_zh":"定义用户到外部服务器的新映射","sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE USER MAPPING\u003c/code\u003e定义用户到外部服务器的映射。用户映射通常封装连接信息，外部数据包装器会将其与外部服务器所封装的信息结合起来，以访问外部数据资源。\u003c/p\u003e\u003cp\u003e外部服务器的拥有者可以创建任意用户到该服务器的用户映射。此外，如果某个用户已被授予该服务器上的\u003ccode class=\"literal\"\u003eUSAGE\u003c/code\u003e权限，那么该用户也可以为自己的用户名创建用户映射。\u003c/p\u003e","key":"description","title":"描述"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eIF NOT EXISTS\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e如果给定用户到给定外部服务器的映射已经存在，则不要报错。这种情况下会发出一个提示。请注意，不能保证现有用户映射与本应创建的映射有任何相似之处。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003euser_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e被映射到外部服务器的现有用户的名称。\u003ccode class=\"literal\"\u003eCURRENT_ROLE\u003c/code\u003e、\u003ccode class=\"literal\"\u003eCURRENT_USER\u003c/code\u003e 和\u003ccode class=\"literal\"\u003eUSER\u003c/code\u003e都匹配当前用户的名称。当指定 \u003ccode class=\"literal\"\u003ePUBLIC\u003c/code\u003e时，会创建一个所谓的公共映射；当没有适用的特定用户映射时，就会使用它。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e将为其创建用户映射的现有服务器的名称。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eOPTIONS ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e '\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e' [, ... ] )\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e该子句指定用户映射的选项。这些选项通常定义该映射实际的用户名和密码。选项名必须唯一。允许的选项名和值取决于该服务器的外部数据包装器。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"参数"},{"html":"\u003cp\u003e为用户\u003ccode class=\"literal\"\u003ebob\u003c/code\u003e、服务器\u003ccode class=\"literal\"\u003efoo\u003c/code\u003e创建一个用户映射：\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE USER MAPPING FOR bob SERVER foo OPTIONS (user 'bob', password 'secret');\n\u003c/pre\u003e","key":"examples","title":"示例"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE USER MAPPING\u003c/code\u003e符合 ISO/IEC 9075-9（SQL/MED）。\u003c/p\u003e","key":"compatibility","title":"兼容性"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/alter-user-mapping/?v=18\" title=\"ALTER USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER USER MAPPING\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-user-mapping/?v=18\" title=\"DROP USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP USER MAPPING\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-foreign-data-wrapper/?v=18\" title=\"CREATE FOREIGN DATA WRAPPER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN DATA WRAPPER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-server/?v=18\" title=\"CREATE SERVER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"另见"}],"sections_same_as":"","synopsis_html":"CREATE USER MAPPING [ IF NOT EXISTS ] FOR { \u003cem class=\"replaceable\"\u003e\u003ccode\u003euser_name\u003c/code\u003e\u003c/em\u003e | USER | CURRENT_ROLE | CURRENT_USER | PUBLIC }\n    SERVER \u003cem class=\"replaceable\"\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/em\u003e\n    [ OPTIONS ( \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e '\u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e' [ , ... ] ) ]","synopsis_text":"CREATE USER MAPPING [ IF NOT EXISTS ] FOR { user_name | USER | CURRENT_ROLE | CURRENT_USER | PUBLIC }\nSERVER server_name\n[ OPTIONS ( option 'value' [ , ... ] ) ]"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
