Thread: list of tables ?

list of tables ?

From
Steve Brett
Date:
can anyone point me in the right direction ?

i need to list all the tables in a database.

i've looked at pgadmin_tables which is empty and pga_schema whihc contains a
sinlge row i don't want to parse ...

is there an easier way t get a list of tables ?

i'm on 7.2

ta,

Steve Brett 




Re: list of tables ?

From
Achilleus Mantzios
Date:
On Thu, 11 Jul 2002, Steve Brett wrote:

> can anyone point me in the right direction ?
> 
> i need to list all the tables in a database.
> 
> i've looked at pgadmin_tables which is empty and pga_schema whihc contains a
> sinlge row i don't want to parse ...
> 
> is there an easier way t get a list of tables ?
> 
> i'm on 7.2

select * from pg_tables;

> 
> ta,
> 
> Steve Brett 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 

-- 
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  achill@matrix.gatewaynet.com       mantzios@softlab.ece.ntua.gr



Re: list of tables ?

From
Ian Barwick
Date:
On Thursday 11 July 2002 16:00, Steve Brett wrote:
> can anyone point me in the right direction ?
>
> i need to list all the tables in a database.
>
> i've looked at pgadmin_tables which is empty and pga_schema whihc contains
> a sinlge row i don't want to parse ...
>
> is there an easier way t get a list of tables ?

Start psql with the -E option and issue \dt

This gives you the statement(s) used internally by psql.


Ian Barwick



Re: list of tables ?

From
Steve Brett
Date:
thanks.

Steve

> -----Original Message-----
> From: Achilleus Mantzios [mailto:achill@matrix.gatewaynet.com]
> Sent: 11 July 2002 15:10
> To: Steve Brett
> Cc: Pgsql-Sql (E-mail)
> Subject: Re: [SQL] list of tables ?
> 
> 
> On Thu, 11 Jul 2002, Steve Brett wrote:
> 
> > can anyone point me in the right direction ?
> > 
> > i need to list all the tables in a database.
> > 
> > i've looked at pgadmin_tables which is empty and pga_schema 
> whihc contains a
> > sinlge row i don't want to parse ...
> > 
> > is there an easier way t get a list of tables ?
> > 
> > i'm on 7.2
> 
> select * from pg_tables;
> 
> > 
> > ta,
> > 
> > Steve Brett 
> > 
> > 
> > 
> > ---------------------------(end of 
> broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> > 
> 
> -- 
> Achilleus Mantzios
> S/W Engineer
> IT dept
> Dynacom Tankers Mngmt
> tel:    +30-10-8981112
> fax:    +30-10-8981877
> email:  achill@matrix.gatewaynet.com
>         mantzios@softlab.ece.ntua.gr
> 


Re: list of tables ?

From
Christoph Haller
Date:
> 
> can anyone point me in the right direction ?
> 
> i need to list all the tables in a database.
> 

Steve, 

Your request reminds me of a similar problem I had. 
Try the following: 

CREATE VIEW sesql_usertables AS
SELECT
UPPER(u.usename) AS tbl_owner, UPPER(c.relname) AS tbl_name,
UPPER(a.attname) AS col_name, a.atttypid AS col_type,
INT4LARGER(a.attlen, a.atttypmod - 4) AS col_length,
CASE WHEN a.attnotnull=TRUE THEN 0 ELSE 1 END AS col_null, a.attnum AS col_seq,CASE WHEN EXISTS(SELECT adsrc FROM
pg_attrdefdWHERE d.adrelid = a.attrelid AND d.adnum = a.attnum) THEN1ELSE0END AS COL_DEFAULT
 
FROM pg_attribute a,    pg_class c LEFT JOIN pg_user u ON (u.usesysid = c.relowner)
WHERE c.oid = a.attrelid AND NOT (c.relname ~* 'pg_') AND     c.relkind = 'r' AND a.attnum > 0 ;

SELECT * FROM sesql_usertables ORDER BY tbl_owner, tbl_name, col_seq ; 

It should give at least some ideas how to retrieve information from all the tables in a database. 

Regards, Christoph