A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/postgresql/postgresql-temporary-table-name/ below:

PostgreSQL - Temporary table name

PostgreSQL - Temporary table name

Last Updated : 15 Jul, 2025

In PostgreSQL, it is possible, though not recommended, to create a temporary table with the same name as an existing permanent table. When a temporary table shares its name with a permanent table, the temporary table will take precedence, preventing access to the permanent table until the temporary table is removed. This behavior can lead to confusion and should be managed carefully.

Let us get a better understanding of the Temporary Table Name in PostgreSQL from this article.

PostgreSQL Temporary table name Example

Let us take a look at an example of the Temporary Table Name in PostgreSQL to better understand the concept.

Step 1: Create a Permanent Table

First, create a permanent table named 'customers'.

Query:

CREATE TABLE customers(
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL
);

This table is now ready to store customer data with unique IDs and names.

Step 2: Create a Temporary Table with the Same Name

Next, create a temporary table named 'customers'.

Query:

CREATE TEMP TABLE customers(
customer_id INT
);
Step 3: Querying the customers Table

Now query the data from the customers table as below.

Query:

SELECT * FROM customers;

Output: PostgreSQL will access the temporary customers table instead of the permanent one. This is because the temporary table takes precedence in the current session.

Step 4: Listing Tables in the Database

If you list the tables in the test database using the \dt command.

\dt

The result is as shown below:

Output: The output will show the temporary 'customers' table, but not the permanent one. The schema for the temporary table will be something like 'pg_temp_3'.

Important Points About PostgreSQL Temporary table name


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4