All Products
Search
Document Center

PolarDB:CREATE SYNONYM

Last Updated:Mar 28, 2026

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

ParameterDescription
syn_nameName of the synonym. Must be unique within a schema.
schemaSchema where the synonym resides. If omitted, the synonym is created in the first existing schema in your search_path.
object_nameName of the referenced object.
object_schemaSchema where the referenced object resides.
dblink_nameDatabase 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;