Aron miles
Aron miles

Reputation: 11

Query for tables returns views too

I want to extract the names of the tables I have.

The code below returns me tables AND views.

   SELECT  quote_ident(table_name) as tab_name
   FROM information_schema.tables
   WHERE table_schema='public'

Question

How can I obtain just the table names and exclude the views?

Upvotes: 1

Views: 234

Answers (1)

RazerM
RazerM

Reputation: 5482

From the documentation (emphasis mine):

The view tables contains all tables and views defined in the current database.

You can use the table_type column to exclude views:

SELECT quote_ident(table_name) as tab_name
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_type != 'VIEW'

Upvotes: 2

Related Questions