Chapter 10. Dealing with the system tables

Table of Contents
Seeing what tables exist
Viewing triggers and their functions
Viewing function bodies
Viewing rules

Seeing what tables exist

You want to check if a table already exists.

Solution

There is a view called pg_tables or the system table pg_class - you can query either. There is less information in pg_tables but it is easier to understand.

SELECT * FROM pg_tables WHERE tablename LIKE 'foo%';

SELECT * FROM pg_class WHERE relname LIKE 'foo%';