Synonyms v14
A synonym is an identifier that you can use to reference another database object in a SQL statement. A synonym is useful in cases where a database object normally requires full qualification by schema name to be properly referenced in a SQL statement. A synonym defined for that object simplifies the reference to a single, unqualified name.
EDB Postgres Advanced Server supports synonyms for:
- Tables
- Views
- Materialized views
- Sequences
- Procedures
- Functions
- Types
- Objects that you can access through a database link
- Other synonyms
Neither the referenced schema or referenced object must exist when you create the synonym. A synonym can refer to a nonexistent object or schema. A synonym becomes invalid if you drop the referenced object or schema. You must explicitly drop a synonym to remove it.
As with any other schema object, EDB Postgres Advanced Server uses the search path to resolve unqualified synonym names. If you have two synonyms with the same name, an unqualified reference to a synonym resolves to the first synonym with the given name in the search path. If public
is in your search path, you can refer to a synonym in that schema without qualifying that name.
When EDB Postgres Advanced Server executes an SQL command, the privileges of the current user are checked against the synonym’s underlying database object. If the user doesn't have the proper permissions for that object, the SQL command fails.
Creating a synonym
Use the CREATE SYNONYM
command to create a synonym. The syntax is: