X-Original-To: pgsql-novice-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4B80C3B474D; Wed, 15 Dec 2004 15:36:09 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69940-10; Wed, 15 Dec 2004 15:35:58 +0000 (GMT) Received: from svarog.thaico.si (p0f.net [193.77.154.190]) by svr1.postgresql.org (Postfix) with ESMTP id AD9F73B46AC; Wed, 15 Dec 2004 15:35:59 +0000 (GMT) Received: from lunik.p0f.net ([192.168.50.128]) by svarog.thaico.si with esmtp (Exim 3.32 #1 (Debian)) id 1CebBq-0004xR-00; Wed, 15 Dec 2004 16:35:46 +0100 Received: from lunik.p0f.net (localhost [127.0.0.1]) by lunik.p0f.net (8.12.10/8.12.10) with ESMTP id iBFFZwSw007471; Wed, 15 Dec 2004 16:35:58 +0100 Received: (from gregab@localhost) by lunik.p0f.net (8.12.10/8.12.10/Submit) id iBFFZw1Z007470; Wed, 15 Dec 2004 16:35:58 +0100 Date: Wed, 15 Dec 2004 16:35:58 +0100 From: Grega Bremec To: sarlav kumar Cc: pgsqlnovice , pgsqlperform Subject: Re: [PERFORM] \d output to a file Message-ID: <20041215153558.GA7419@lunik.p0f.net> References: <20041215143822.37534.qmail@web51304.mail.yahoo.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="0OAP2g/MAC+5xKAE" Content-Disposition: inline In-Reply-To: <20041215143822.37534.qmail@web51304.mail.yahoo.com> User-Agent: Mutt/1.4.1i Organization: p0f X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.705 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, RCVD_IN_NJABL_DUL X-Spam-Level: * X-Archive-Number: 200412/158 X-Sequence-Number: 11735 --0OAP2g/MAC+5xKAE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable =2E..and on Wed, Dec 15, 2004 at 06:38:22AM -0800, sarlav kumar used the ke= yboard: > Hi All, > =20 > I would like to write the output of the \d command on all tables in a dat= abase 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 th= ere 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. > =20 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=3D$1 MYTABLES=3D"`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, --=20 Grega Bremec gregab at p0f dot net --0OAP2g/MAC+5xKAE Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFBwFnefu4IwuB3+XoRAvaxAJ0YdErCui8t2ak6NxyCxiQpxdOYeACfSz3y eznxq1PM4fn0tm1XkkJ9kck= =NgiN -----END PGP SIGNATURE----- --0OAP2g/MAC+5xKAE--