postgresqlHow do I create a temporary table in PostgreSQL?
Creating a temporary table in PostgreSQL is a simple process. Here is an example of how to do it:
-- Create a temporary table
CREATE TEMP TABLE items (
id INTEGER,
name VARCHAR(50)
);
-- Insert some data
INSERT INTO items (id, name)
VALUES (1, 'Apple'), (2, 'Banana'), (3, 'Orange');
-- Select the data
SELECT * FROM items;
-- Output
id | name
----+--------
1 | Apple
2 | Banana
3 | Orange
The code above creates a temporary table called items
with two columns, id
and name
. Then it inserts a few rows of data into the table. Finally, it selects the data from the table and prints the output.
The key parts of the code are:
CREATE TEMP TABLE
- creates a temporary tableINSERT INTO
- inserts data into the tableSELECT * FROM
- selects data from the table
For more information, see the PostgreSQL documentation:
More of Postgresql
- How can I use PostgreSQL XOR to compare two values?
- How can I use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can Zalando use PostgreSQL to improve its software development?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I integrate PostgreSQL with Yii2?
- How can I use PostgreSQL with YAML?
- How do I install and configure PostgreSQL on a Windows machine?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I set a PostgreSQL interval to zero?
See more codes...