Javatpoint Logo
Javatpoint Logo

PostgreSQL Alias

PostgreSQL Aliases are used to provide temporary names for columns or tables. You can create a temporary name for a column or a table by using PostgreSQL Alias.

Generally a temporary table is created when you perform self join.


PostgreSQL Alias Column

Syntax:

Parameter explanation:

column_name: It specifies the original name of the column that you want to alias.

alias_name: It specifies the temporary name that is assigned to the column.

table_name: It specifies the name of the table.

AS: It is optional. Most programmers will specify the AS keyword when aliasing a column name, but not when aliasing a table name.

Note:

  • If the alias_name contains spaces, you must enclose the alias_name in quotes.
  • It is acceptable to use spaces when you are aliasing a column name. However, it is not generally a good practice to use spaces when you are aliasing a table name.
  • The alias_name is only valid within the scope of the SQL statement.

See this example:

Let's take a table "EMPLOYEES" having the following data.

EMPLOYEES Table

postgresql-alias1

Execute the following query:

Output:

postgresql-alias2

PostgreSQL Alias Table

Syntax:

Parameter explanation:

table_name: It specifies the original name of the table that you want to alias.

alias_name: It specifies the temporary name that is assigned to the table.

AS: It is optional. Most programmers will specify the AS keyword when aliasing a column name, but not when aliasing a table name.

Note:

  • If the alias_name contains spaces, you must enclose the alias_name in quotes.
  • It is acceptable to use spaces when you are aliasing a column name. However, it is not generally a good practice to use spaces when you are aliasing a table name.
  • The alias_name is only valid within the scope of the SQL statement.

Let's take a table "EMPLOYEES" having the following data.

Table1: EMPLOYEES

postgresql-alias3

Create another table "DEPARTMENT" having the following data.

Table2: DEPARTMENT

postgresql-alias4

Now, following is the usage of TABLE ALIAS where we use E and D as aliases for EMPLOYEES and DEPARTMENT tables, respectively:

Execute the following query:

Output:

postgresql-alias5
Next TopicPostgreSQL Indexes




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA