| From: | José Soares <jose(at)sferacarta(dot)com> | 
|---|---|
| To: | Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us> | 
| Cc: | Scott Barron <kain224(at)yahoo(dot)com>, Albert REINER <areiner(at)tph(dot)tuwien(dot)ac(dot)at>, PostgreSQL-SQL <pgsql-sql(at)postgresql(dot)org> | 
| Subject: | Re: [SQL] Expression with aggregate | 
| Date: | 1999-08-24 13:37:23 | 
| Message-ID: | 37C2A012.C400A443@sferacarta.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-sql | 
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(at)tph(dot)tuwien(dot)ac(dot)at>
> > >
> > ---------------------------------------------------------------------------
> > >
> > > ************
> > >
> > >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Bid and sell for free at http://auctions.yahoo.com
> >
> >
> > ************
> >
> >
>
> --
>   Bruce Momjian                        |  http://www.op.net/~candle
>   maillist(at)candle(dot)pha(dot)pa(dot)us            |  (610) 853-3000
>   +  If your life is a hard drive,     |  830 Blythe Avenue
>   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
>
> ************
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Greg Youngblood | 1999-08-24 15:38:32 | RE: [SQL] Accessing to a granted table. | 
| Previous Message | Drinks, Ivan - ITD | 1999-08-24 11:51:27 | Remove |