Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL : programmatically determine if table is view

Tags:

sql

postgresql

If I need to determine if a given table is a view, can I do this with a query instead of using '\d' ? I have a script that needs to audit several tables for deletion but don't want to check them all manually.

like image 649
JacobIRR Avatar asked Oct 19 '25 05:10

JacobIRR


1 Answers

You can find that information from the information_schema.tables view:

select table_type 
from information_schema.tables 
where table_schema = 'my_schema' and table_name = 'my_table'

table_type column description:

Type of the table: BASE TABLE for a persistent base table (the normal table type), VIEW for a view, FOREIGN TABLE for a foreign table, or LOCAL TEMPORARY for a temporary table

like image 57
binoternary Avatar answered Oct 21 '25 18:10

binoternary