PostgreSQL aliases are powerful tools that allow you to assign temporary names to tables or columns within your queries. These aliases only exist during the execution of the query, making your SQL code more readable and efficient.
What is a PostgreSQL Alias?
An alias in PostgreSQL is a temporary name given to a table or column. This can help simplify complex queries, improve readability, and make it easier to reference tables and columns.
For the sake of this article, we will be using the sample DVD rental database, which is explained here and can be downloaded by clicking on this link in our examples.
Column Aliases in PostgreSQL
Column aliases allow you to rename the columns in the result set of your query, making the output more meaningful.
Syntax
SELECT column_name AS alias_name FROM table;
or,
SELECT column_name alias_name FROM table;
You can also use column aliases with expressions.
SELECT expression alias_name FROM table;
The primary use of column alias is to make the output of a query more meaningful. The below example illustrates the use of column alias:
Example: Using Column Aliases
Here we will make a query to get full name of the customers from the "customer" table using column alias.
Query:
SELECT
first_name || ' ' || last_name AS full_name
FROM
customer
ORDER BY
full_name;
Output:

Explanation: This query concatenates the 'first_name' and 'last_name' columns into a single 'full_name' column for better readability.
Table Aliases in PostgreSQL
Table aliases provide a way to shorten table names in your queries, especially useful for tables with long names or when joining multiple tables.
Syntax
SELECT column_list FROM table_name AS alias_name;
or,
SELECT column_list FROM table_name alias_name;
Use Cases
There are multiple use-cases for table alias. Few of them are listed below:
- It can be used to save some keystrokes and make your query more readable for tables with long names.
- It can also be used when you query data from multiple tables that have the same column names.
- It can be used to join a table with itself (ie, SELF JOIN).
Example: Using Table Aliases
Here we will be using table alias to avoid writing "address" for each column instead use a short form "add" as an alias to get the "district" and "postal_code" column from the "address" table of our database.
Query:
SELECT add.postal_code,
add.district
FROM address add;
Output:

Explanation: This query uses 'add' as an alias for the 'address' table, making the query shorter and easier to read.
Similar Reads
PostgreSQL - INSERT PostgreSQL INSERT statement is one of the fundamental SQL commands used to add new rows to a specified table within a PostgreSQL database. This command allows users to insert data efficiently, whether for a single record or multiple records at once. With the PostgreSQL INSERT INTO clause, we can spe
4 min read
PostgreSQL - GRANT In PostgreSQL, the GRANT statement is a powerful tool used to assign privileges to a role, allowing it to alter database objects like tables, views, functions, and more. Here we will learn about the syntax and application of the GRANT statement, with examples to illustrate its usage in PostgreSQL.Sy
3 min read
PostgreSQL ALTER DATABASE The PostgreSQL ALTER DATABASE statement is a powerful tool used for modifying an existing database.  The features of a database, once created can be changed using the ALTER DATABASE statement. Let's explore the syntax of PostgreSQL ALTER DATABASE, the various actions that can be performed, and pract
3 min read
PostgreSQL Exercises PostgreSQL is a powerful, open-source relational database system that supports complex queries, data types, and performance optimization features. This article provides PostgreSQL practice exercises with solutions, allowing learners to explore how joins, aggregations, triggers, and foreign keys work
15+ min read
PostgreSQL - WHERE clause The PostgreSQL WHERE clause is a critical component of SQL queries, allowing users to filter records based on specified conditions. In this tutorial, we'll explore how the WHERE clause works in PostgreSQL, its integration with the SELECT statement, and various examples. By using the WHERE clause, we
6 min read