From: | googlemike(at)hotpop(dot)com (Google Mike) |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | HOWTO: Get a table or database definition |
Date: | 2004-09-04 20:53:48 |
Message-ID: | 25d8d6a8.0409041253.7e48fe94@posting.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I guess it would be great if Pgsql had a way to find a database
definition via a system stored procedure like other database platforms
have.
There are two ways I've found so far:
SELECT
attname as "name", typname as "type", atttypmod - 4 as "size",
relhaspkey as "is_primary_key", *
FROM
pg_class AS a
LEFT OUTER JOIN pg_attribute AS b ON (b.attrelid = a.oid)
LEFT OUTER JOIN pg_type AS c ON (b.atttypid = c.oid)
where a.relname = 'names' and b.attstattarget = -1
order by attnum;
...yields great results for a table called 'names'
The other way is:
pg_dump -h localhost -p 5432 -U root -s -C test | grep -i "CREATE" -A
500000 | grep -v "\-\-" | grep -v "\\connect" | grep -v "SET " | tr -s
"\n"
...shows me a result for host 'localhost', port '5432', user 'root',
database 'test'
From | Date | Subject | |
---|---|---|---|
Next Message | W. Scott Gibson | 2004-09-04 21:09:45 | Re: How do I list the schema for a table or procedure? |
Previous Message | Wes | 2004-09-04 20:51:24 | Re: How to determine a database is intact? |