Creates a synonym for a database object.
Synonyms provide location transparency and object abstraction — applications can reference the synonym name without knowing which schema owns the underlying object or where it resides. Synonyms are not a substitute for permissions: the user must still have the required privileges on the underlying object.
Syntax
CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema.]syn_name
FOR object_schema.object_name[@dblink_name];Parameters
| Parameter | Description |
|---|---|
syn_name | Name of the synonym. Must be unique within a schema. |
schema | Schema where the synonym resides. If omitted, the synonym is created in the first existing schema in your search_path. |
object_name | Name of the referenced object. |
object_schema | Schema where the referenced object resides. |
dblink_name | Database link through which the object is accessed. |
Usage notes
OR REPLACE: Replaces an existing synonym definition with a new one without dropping and recreating it.
PUBLIC: Creates the synonym in the public schema. The PUBLIC SYNONYM command is compatible with Oracle databases. The following two forms are equivalent:
CREATE [OR REPLACE] PUBLIC SYNONYM syn_name FOR object_schema.object_name;CREATE [OR REPLACE] SYNONYM public.syn_name FOR object_schema.object_name;Supported object types: PolarDB for PostgreSQL (Compatible with Oracle) supports synonyms for the following object types:
Tables
Views
Materialized views
Sequences
Stored procedures
Stored functions
Types
Objects accessible through a database link
Other synonyms
Access control: Access to the object referenced by a synonym is determined by the privileges of the current user. The user must have the required privileges on the underlying object.
Examples
Create a private synonym for a table
CREATE SYNONYM personnel FOR polardb.emp;