Re: pg_views

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Lex Berezhny <LBerezhny(at)DevIS(dot)com>
Cc: "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: pg_views
Date: 2003-02-04 17:36:03
Message-ID: 3E3FFA03.F0EF4D64@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Lex Berezhny wrote:
>
> hi,
>
> I'm trying to write some code that can analyze the database structure
> and i need a way to discover the composition of a view (the tables and
> table.column info).
>
> I've managed to do much of this by querying the pg_views for the
> definition and literally parsing the SQL myself, but obviously that has
> many limitations unless I impliment a complete SQL parser and that's
> beyond the scope of what I want :-)
>
> I'm wondering if PostgreSQL actually reparses the view definition on
> each invocation or if it stores the required information in some
> accessible place.
>
> My goal is to take a view name as input and output the tables and
> columns composing the view.

Don't forget that a view's columns can contain complex expressions
instead of simple table.column references.

The place where the real information about views is stored is
pg_rewrite. pg_views is a view itself, using a function that parses back
the rewrite rule into a human readable format. There are people around
who can read the querytree format stored in pg_rewrite as well.

So parsing pg_views output would be ... er ... parsing a query string
that was reconstructed from a parsetree that resulted from parsing a
query string ... that doesn't sound like the right thing to do.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

  • pg_views at 2003-02-04 02:34:03 from Lex Berezhny

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Wieck 2003-02-04 18:06:20 Re: iceberg queries
Previous Message Bruno Wolff III 2003-02-04 15:50:13 Re: iceberg queries