Materialized views don't show up in information_schema

From: Sehrope Sarkuni <sehrope(at)jackdb(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Materialized views don't show up in information_schema
Date: 2014-10-10 22:31:20
Message-ID: CAH7T-ao6ece1mgCsCvsE04W59ZZJP9gGXVK97wkUzRV5gsDqQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I've been testing out some of the new materialized view functionality
in 9.4 and noticed that they don't show up in the information_schema
data dictionary views, specifically information_schema.tables or
information_schema.views (sample output is below and it's the same for
9.3 as well).

Is this on purpose or just an oversight?

I think they should at least be in the information_schema.views view,
though the case could be made that they should be in
information_schema.tables as well (as they can have additional
indexes). If they're added to the tables view then they should have a
separate table_type (say, "MATERIALIZED VIEW"), similar to how foreign
tables show up.

Looking at the view definitions, it looks like it's just a matter of
adding 'm' values to the IN clauses that filter pg_class.relkind. It
doesn't look like they're used internally by anything other than
tests. Only client apps that query the data dictionary views (ex: GUI
clients or dynamic SQL generators) would be impacted. I'd argue it's
for the better as they can they can now see those objects, even if
they think they're regular tables or views.

If this sound fine I can put together a patch for this.

Regards,
-- Sehrope Sarkuni

postgres(at)vagrant-ubuntu-trusty-64:~$ psql test
psql (9.4beta3)
Type "help" for help.

test=# CREATE TABLE some_table (x text);
CREATE TABLE

test=# CREATE MATERIALIZED VIEW some_mview AS SELECT * FROM some_table;
SELECT 0

test=# CREATE VIEW some_view AS SELECT * FROM some_table;
CREATE VIEW

test=# \d some_mview
Materialized view "public.some_mview"
Column | Type | Modifiers
--------+------+-----------
x | text |

test=# SELECT table_name, table_type FROM information_schema.tables
WHERE table_schema = 'public';
table_name | table_type
------------+------------
some_table | BASE TABLE
some_view | VIEW
(2 rows)

test=# SELECT table_name, view_definition FROM
information_schema.views WHERE table_schema = 'public';
table_name | view_definition
------------+----------------------
some_view | SELECT some_table.x+
| FROM some_table;
(1 row)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-10-10 22:38:06 Re: Materialized views don't show up in information_schema
Previous Message Peter Geoghegan 2014-10-10 22:03:08 Re: UPSERT wiki page, and SQL MERGE syntax