How to check if a PostgreSQL table is temporary?
-
27-12-2020 - |
Question
How can I write a query to check if a PostgreSQL (10.x) table is a temporary table?
I looked at the pg_class
system table, but couldn't find any column about whether the relation is temporary.
SELECT * FROM pg_class WHERE False;
relname | relnamespace | reltype | reloftype | relowner | relam | relfilenode | reltablespace | relpages | reltuples | relallvisible | reltoastrelid | relhasindex | relisshared | relpersistence | relkind | relnatts | relchecks | relhasoids | relhaspkey | relhasrules | relhastriggers | relhassubclass | relrowsecurity | relforcerowsecurity | relispopulated | relreplident | relispartition | relfrozenxid | relminmxid | relacl | reloptions | relpartbound
---------+--------------+---------+-----------+----------+-------+-------------+---------------+----------+-----------+---------------+---------------+-------------+-------------+----------------+---------+----------+-----------+------------+------------+-------------+----------------+----------------+----------------+---------------------+----------------+--------------+----------------+--------------+------------+--------+------------+--------------
(0 rows)
Solution
relpersistence: p = permanent table, u = unlogged table, t = temporary table
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange