pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: José Soares <jose@sferacarta.com>
To: Bruce Momjian <maillist@candle.pha.pa.us>
Cc: Scott Barron <kain224@yahoo.com>
Cc: Albert REINER <areiner@tph.tuwien.ac.at>
Cc: PostgreSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: [SQL] Expression with aggregate
Date: Tue, 24 Aug 1999 15:37:23 +0200
Message-ID: <37C2A012.C400A443@sferacarta.com> (raw)
References: <199908240424.AAA16390@candle.pha.pa.us>

In PostgreSQL a view is a table with a special rule named: "_RETnametable" where
nametable stands for the table name used by the view.

eg:
CREATE RULE "_RETvista" AS ON SELECT TO "vista" DO INSTEAD SELECT "a" FROM
"tabella";

Actually, psql checks in the field pg_class.relkind to see if it is a table or
other kind of class ('i'=index, S=sequence, 'r'=table/view, etc).
If psql finds a 'r' into pg_class.relkind then it checks in the boolean field
pg_class.relhasrules and prints "table" if its value is FALSE or "view?" if its
value is TRUE.
The field pg_class.relhasrules is also used for every kind of rule in the table,
this is the reason why psql prints "view?" because it doesn't know for sure if
the rule is
a "_RET..." (view) or other kind of rule.


QUERY: SELECT usename, relname, relkind, relhasrules FROM pg_class, pg_user WHER
E usesysid = relowner and ( relkind = 'r' OR relkind = 'i' OR relkind = 'S') and
 relname !~ '^pg_' and (relkind != 'i' OR relname !~ '^xinx')  ORDER BY relname

Database    = prova
 +------------------+----------------------------------+----------+
 |  Owner           |             Relation             |   Type   |
 +------------------+----------------------------------+----------+
 | postgres         | serial                           | sequence |
 | postgres         | t_a_seq                          | sequence |
 | postgres         | tabella                          | table    |
 | postgres         | vista                            | view?    |
 +------------------+----------------------------------+----------+

There's an exactly way to know if the table is a view or a table; the function
pg_get_viewdef()
But I don't know why psql doesn't use it...


prova=> select pg_get_viewdef('vista');
pg_get_viewdef
--------------------------
SELECT "a" FROM "tabella";
(1 row)


prova=> select pg_get_viewdef('tabella');
pg_get_viewdef
--------------
Not a view
(1 row)



José



Bruce Momjian ha scritto:

> >
> > That should provide the desired results.  As for the
> > question about the view in the \d output, I don't know
> > why its like that, I've wondered myself.
>
> I think it is view? because it could be a view, or a rule?
>
> > >
> > > By the way, when I use \d to list the tables, why is
> > > a view always
> > > shown with a '?' like in
> > >
> > > asdf=> \d
> > > Database    = asdf
> > >
> > >
> > +------------------+----------------------------------+----------+
> > >  |  Owner           |             Relation
> > >   |   Type   |
> > >
> > >
> > +------------------+----------------------------------+----------+
> > >  | albert           | a
> > >   | table    |
> > >  | albert           | b
> > >   | table    |
> > >  | albert           | c
> > >   | view?    |
> > >
> > >
> > +------------------+----------------------------------+----------+
> > >
> > > ? Why doesn't it just say '| albert | c | view |'?
> > >
> > > I'd really appreciate any hints with this, even
> > > though I know how to
> > > do it (as demonstrated above) with the use of the
> > > view.
> > >
> > > Thanks in advance for your help,
> > >
> > > Albert.
> > >
> > > --
> > >
> > >
> > ---------------------------------------------------------------------------
> > >   Post an / Mail to / Skribu al: Albert Reiner
> > > <areiner@tph.tuwien.ac.at>
> > >
> > ---------------------------------------------------------------------------
> > >
> > > ************
> > >
> > >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Bid and sell for free at http://auctions.yahoo.com
> >
> >
> > ************
> >
> >
>
> --
>   Bruce Momjian                        |  http://www.op.net/~candle
>   maillist@candle.pha.pa.us            |  (610) 853-3000
>   +  If your life is a hard drive,     |  830 Blythe Avenue
>   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
>
> ************

view thread (4+ messages)

Message-ID: <37C2A012.C400A443@sferacarta.com>
Permalink:  ../37C2A012.C400A443@sferacarta.com/
Also on:    postgresql.org/message-id/37C2A012.C400A443@sferacarta.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: jose@sferacarta.com, maillist@candle.pha.pa.us, kain224@yahoo.com, areiner@tph.tuwien.ac.at
  Subject: Re: [SQL] Expression with aggregate
  In-Reply-To: <37C2A012.C400A443@sferacarta.com>
  References: <199908240424.AAA16390@candle.pha.pa.us> <37C2A012.C400A443@sferacarta.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox