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 do I parse XML data using PostgreSQL?
- How can Zalando use PostgreSQL to improve its software development?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL and ZFS together?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I use PostgreSQL with YAML?
See more codes...