pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feed\d output to a file
10+ messages / 8 participants
[nested] [flat]
* \d output to a file
@ 2004-12-15 14:38 sarlav kumar <sarlavk@yahoo.com>
2004-12-15 15:04 ` Re: [despammed] \d output to a file Andreas Kretschmer <akretschmer@despammed.com>
2004-12-15 15:12 ` Re: [PERFORM] \d output to a file Gary Cowell <gary.cowell@gmail.com>
2004-12-15 15:17 ` Re: \d output to a file Geoffrey <esoteric@3times25.net>
2004-12-15 15:35 ` Re: [PERFORM] \d output to a file Grega Bremec <gregab@p0f.net>
0 siblings, 4 replies; 10+ messages in thread
From: sarlav kumar @ 2004-12-15 14:38 UTC (permalink / raw)
To: pgsqlnovice <pgsql-novice@postgresql.org>; pgsql-performance
Hi All,
I would like to write the output of the \d command on all tables in a database to an output file. There are more than 200 tables in the database. I am aware of \o command to write the output to a file. But, it will be tough to do the \d for each table manually and write the output to a file. Is there a command/ way in which I can achieve this without having to do it for each table?
Any help in this regard would be really appreciated.
Thanks,
Saranya
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: [despammed] \d output to a file
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
@ 2004-12-15 15:04 ` Andreas Kretschmer <akretschmer@despammed.com>
2004-12-15 15:23 ` Re: [despammed] \d output to a file Geoffrey <esoteric@3times25.net>
3 siblings, 1 reply; 10+ messages in thread
From: Andreas Kretschmer @ 2004-12-15 15:04 UTC (permalink / raw)
To: pgsqlnovice <pgsql-novice@postgresql.org>
am 15.12.2004, um 6:38:22 -0800 mailte sarlav kumar folgendes:
> Hi All,
>
> I would like to write the output of the \d command on all tables in a database to an output file. There are more than 200 tables in the database. I am aware of \o command to write the output to a file. But, it will be tough to do the \d for each table manually and write the output to a file. Is there a command/ way in which I can achieve this without having to do it for each table?
> Any help in this regard would be really appreciated.
You can write a little shell-script to list all tables via \d and parse
the output to generate for each table a '\d table'.
Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Tel. NL Heynitz: 035242/47212
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: [despammed] \d output to a file
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
2004-12-15 15:04 ` Re: [despammed] \d output to a file Andreas Kretschmer <akretschmer@despammed.com>
@ 2004-12-15 15:23 ` Geoffrey <esoteric@3times25.net>
2004-12-15 16:21 ` Re: [despammed] \d output to a file Kretschmer Andreas <andreas_kretschmer@despammed.com>
0 siblings, 1 reply; 10+ messages in thread
From: Geoffrey @ 2004-12-15 15:23 UTC (permalink / raw)
To: pgsqlnovice <pgsql-novice@postgresql.org>
Andreas Kretschmer wrote:
> am 15.12.2004, um 6:38:22 -0800 mailte sarlav kumar folgendes:
>
>>Hi All,
>>
>>I would like to write the output of the \d command on all tables in a database to an output file. There are more than 200 tables in the database. I am aware of \o command to write the output to a file. But, it will be tough to do the \d for each table manually and write the output to a file. Is there a command/ way in which I can achieve this without having to do it for each table?
>>Any help in this regard would be really appreciated.
>
>
> You can write a little shell-script to list all tables via \d and parse
> the output to generate for each table a '\d table'.
Or:
for table in $(<filethatcontainsalistofthetables); do
echo "\d $table" | psql $DATABASE > ${table}.out
done
--
Until later, Geoffrey
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: [despammed] \d output to a file
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
2004-12-15 15:04 ` Re: [despammed] \d output to a file Andreas Kretschmer <akretschmer@despammed.com>
2004-12-15 15:23 ` Re: [despammed] \d output to a file Geoffrey <esoteric@3times25.net>
@ 2004-12-15 16:21 ` Kretschmer Andreas <andreas_kretschmer@despammed.com>
0 siblings, 0 replies; 10+ messages in thread
From: Kretschmer Andreas @ 2004-12-15 16:21 UTC (permalink / raw)
To: pgsqlnovice <pgsql-novice@postgresql.org>
am Wed, dem 15.12.2004, um 10:23:54 -0500 mailte Geoffrey folgendes:
> >>I would like to write the output of the \d command on all tables in a
> >>database to an output file. There are more than 200 tables in the
> >>database. I am aware of \o command to write the output to a file. But, it
> >>will be tough to do the \d for each table manually and write the output
> >>to a file. Is there a command/ way in which I can achieve this without
> >>having to do it for each table?
> >
> >You can write a little shell-script to list all tables via \d and parse
> >the output to generate for each table a '\d table'.
>
> Or:
>
> for table in $(<filethatcontainsalistofthetables); do
Yes, but you need the file called 'filethatcontainsalistofthetables' ;-)
echo "\d" | psql test_db | awk 'BEGIN{FS="|"}{if($3 ~ "Tabelle") {print "\d" $2}}' | psql test_db
It works, if the database named 'test_db' and if the output from \d in
the 3th row is 'Tabelle'.
Andreas
--
Diese Message wurde erstellt mit freundlicher Unterstützung eines freilau-
fenden Pinguins aus artgerechter Freilandhaltung. Er ist garantiert frei
von Micro$oft'schen Viren. (#97922 http://counter.li.org) GPG 7F4584DA
Was, Sie wissen nicht, wo Kaufbach ist? Hier: N 51.05082°, E 13.56889° ;-)
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: [PERFORM] \d output to a file
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
@ 2004-12-15 15:12 ` Gary Cowell <gary.cowell@gmail.com>
3 siblings, 0 replies; 10+ messages in thread
From: Gary Cowell @ 2004-12-15 15:12 UTC (permalink / raw)
To: pgsqlnovice <pgsql-novice@postgresql.org>; pgsql-performance
On Wed, 15 Dec 2004 06:38:22 -0800 (PST), sarlav kumar
<sarlavk@yahoo.com> wrote:
> Hi All,
>
> I would like to write the output of the \d command on all tables in a
> database to an output file. There are more than 200 tables in the database.
> I am aware of \o command to write the output to a file. But, it will be
> tough to do the \d for each table manually and write the output to a file.
> Is there a command/ way in which I can achieve this without having to do it
> for each table?
> Any help in this regard would be really appreciated.
>
> Thanks,
> Saranya
>
>
Try something like:
psql -c "\d *" >listing.txt
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: \d output to a file
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
@ 2004-12-15 15:17 ` Geoffrey <esoteric@3times25.net>
2004-12-15 16:50 ` Re: \d output to a file Tom Lane <tgl@sss.pgh.pa.us>
3 siblings, 1 reply; 10+ messages in thread
From: Geoffrey @ 2004-12-15 15:17 UTC (permalink / raw)
To: pgsqlnovice <pgsql-novice@postgresql.org>; pgsql-performance
sarlav kumar wrote:
> Hi All,
>
> I would like to write the output of the \d command on all tables in a
> database to an output file. There are more than 200 tables in the
> database. I am aware of \o command to write the output to a file.
> But, it will be tough to do the \d for each table manually and write
> the output to a file. Is there a command/ way in which I can achieve
> this without having to do it for each table? Any help in this regard
> would be really appreciated.
What is the OS? On any UNIX variant you can do:
echo '\d' | psql > outputfile
But this will get you the system tables as well I think.
Alternately you could do something like:
for table in $(<listoftables); do
echo '\d' | psql
done > outputfile
--
Until later, Geoffrey
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: \d output to a file
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
2004-12-15 15:17 ` Re: \d output to a file Geoffrey <esoteric@3times25.net>
@ 2004-12-15 16:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-12-15 18:04 ` Re: \d output to a file Kretschmer Andreas <andreas_kretschmer@despammed.com>
2004-12-15 18:23 ` Re: [PERFORM] \d output to a file Ragnar Hafstað <gnari@simnet.is>
0 siblings, 2 replies; 10+ messages in thread
From: Tom Lane @ 2004-12-15 16:50 UTC (permalink / raw)
To: Geoffrey <esoteric@3times25.net>; +Cc: pgsqlnovice <pgsql-novice@postgresql.org>; pgsql-performance
Geoffrey <esoteric@3times25.net> writes:
> sarlav kumar wrote:
>> I would like to write the output of the \d command on all tables in a
>> database to an output file.
> What is the OS? On any UNIX variant you can do:
> echo '\d' | psql > outputfile
Or use \o:
regression=# \o zzz1
regression=# \d
regression=# \o
regression=# \d
List of relations
Schema | Name | Type | Owner
--------+---------------+-------+----------
public | pg_ts_cfg | table | postgres
public | pg_ts_cfgmap | table | postgres
public | pg_ts_dict | table | postgres
public | pg_ts_parser | table | postgres
public | t_test | table | postgres
public | test_tsvector | table | postgres
(6 rows)
regression=# \q
$ cat zzz1
List of relations
Schema | Name | Type | Owner
--------+---------------+-------+----------
public | pg_ts_cfg | table | postgres
public | pg_ts_cfgmap | table | postgres
public | pg_ts_dict | table | postgres
public | pg_ts_parser | table | postgres
public | t_test | table | postgres
public | test_tsvector | table | postgres
(6 rows)
$
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: \d output to a file
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
2004-12-15 15:17 ` Re: \d output to a file Geoffrey <esoteric@3times25.net>
2004-12-15 16:50 ` Re: \d output to a file Tom Lane <tgl@sss.pgh.pa.us>
@ 2004-12-15 18:04 ` Kretschmer Andreas <andreas_kretschmer@despammed.com>
1 sibling, 0 replies; 10+ messages in thread
From: Kretschmer Andreas @ 2004-12-15 18:04 UTC (permalink / raw)
To: pgsqlnovice <pgsql-novice@postgresql.org>
am Wed, dem 15.12.2004, um 11:50:58 -0500 mailte Tom Lane folgendes:
> Geoffrey <esoteric@3times25.net> writes:
> > sarlav kumar wrote:
> >> I would like to write the output of the \d command on all tables in a
> >> database to an output file.
I remember: '\d command on all tables'
And you wrote:
>
> regression=# \q
> $ cat zzz1
> List of relations
> Schema | Name | Type | Owner
> --------+---------------+-------+----------
> public | pg_ts_cfg | table | postgres
> public | pg_ts_cfgmap | table | postgres
Sorry, but i think, this isn't the correct answer...
Andreas, leaning PostgreSQL and english...
--
Diese Message wurde erstellt mit freundlicher Unterstützung eines freilau-
fenden Pinguins aus artgerechter Freilandhaltung. Er ist garantiert frei
von Micro$oft'schen Viren. (#97922 http://counter.li.org) GPG 7F4584DA
Was, Sie wissen nicht, wo Kaufbach ist? Hier: N 51.05082°, E 13.56889° ;-)
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: [PERFORM] \d output to a file
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
2004-12-15 15:17 ` Re: \d output to a file Geoffrey <esoteric@3times25.net>
2004-12-15 16:50 ` Re: \d output to a file Tom Lane <tgl@sss.pgh.pa.us>
@ 2004-12-15 18:23 ` Ragnar Hafstað <gnari@simnet.is>
1 sibling, 0 replies; 10+ messages in thread
From: Ragnar Hafstað @ 2004-12-15 18:23 UTC (permalink / raw)
To: sarlav kumar <sarlavk@yahoo.com>; +Cc: pgsqlnovice <pgsql-novice@postgresql.org>; pgsql-performance
On Wed, 2004-12-15 at 11:50 -0500, Tom Lane wrote:
> Geoffrey <esoteric@3times25.net> writes:
> > sarlav kumar wrote:
> >> I would like to write the output of the \d command on all tables in a
> >> database to an output file.
>
> > What is the OS? On any UNIX variant you can do:
> > echo '\d' | psql > outputfile
>
> Or use \o:
>
> regression=# \o zzz1
> regression=# \d
or:
=# \d *
to get all tables as th OP wanted
> regression=# \o
gnari
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: [PERFORM] \d output to a file
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
@ 2004-12-15 15:35 ` Grega Bremec <gregab@p0f.net>
3 siblings, 0 replies; 10+ messages in thread
From: Grega Bremec @ 2004-12-15 15:35 UTC (permalink / raw)
To: sarlav kumar <sarlavk@yahoo.com>; +Cc: pgsqlnovice <pgsql-novice@postgresql.org>; pgsql-performance
...and on Wed, Dec 15, 2004 at 06:38:22AM -0800, sarlav kumar used the keyboard:
> Hi All,
>
> I would like to write the output of the \d command on all tables in a database to an output file. There are more than 200 tables in the database. I am aware of \o command to write the output to a file. But, it will be tough to do the \d for each table manually and write the output to a file. Is there a command/ way in which I can achieve this without having to do it for each table?
> Any help in this regard would be really appreciated.
>
Hello Sarlav.
You don't say which platform you're doing this on. If it's Windows, someone
else will have to advise you; if it's a UNIX-like platform though, the
following simple shell script should be helpful in achieving what you want:
---CUT-HERE---
#!/bin/bash
if [ -z "$1" ]; then
echo "Please specify a database to query."
exit 1
fi
DATABASE=$1
MYTABLES="`echo '\t\a\dt' | psql -q ${DATABASE} | cut -f 2 -d '|'`"
for table in ${MYTABLES}; do
echo '\d '${table}
done | psql ${DATABASE}
---CUT-HERE---
You can store this script into a file called, for example, describe.sh and
invoke it like so:
$ ./describe.sh mydatabase > description.txt
It should then do what you want.
Should you have additional arguments to specify to psql, such as a host,
a username, a password and so on, it is easy to modify the script to do
that. Just supply those arguments in places where the "psql" command is
used.
Hope this helped,
--
Grega Bremec
gregab at p0f dot net
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2004-12-15 18:23 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-12-15 14:38 \d output to a file sarlav kumar <sarlavk@yahoo.com>
2004-12-15 15:04 ` Andreas Kretschmer <akretschmer@despammed.com>
2004-12-15 15:23 ` Geoffrey <esoteric@3times25.net>
2004-12-15 16:21 ` Kretschmer Andreas <andreas_kretschmer@despammed.com>
2004-12-15 15:12 ` Gary Cowell <gary.cowell@gmail.com>
2004-12-15 15:17 ` Geoffrey <esoteric@3times25.net>
2004-12-15 16:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-12-15 18:04 ` Kretschmer Andreas <andreas_kretschmer@despammed.com>
2004-12-15 18:23 ` Ragnar Hafstað <gnari@simnet.is>
2004-12-15 15:35 ` Grega Bremec <gregab@p0f.net>
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