sql script questions
Howdy:
Please redirect me if this is the wrong group. My question
is pretty much SQL related for Postres.
I want to write a script (either shell or SQL) to:
1) get a list of tables
2) get the list of attributes, type and modifyer
of each table.
It is something in the way of:
for i in `\d`
do
\d $i
done
As far as I can tell, '\d' describes a table, view or what
have you. '\d' alone gives me a list of tables and views I
have in my database.
Any examples out there that does this?
TIA!
-X
Okay:
i figured out my problem through a shell script.
yeah, it probably seems real easy, i just don't
have many people to bounce ideas off of.
anyway - what i wanted was to to into postgres,
get a list of tables and their attributes and
send them to individual files for documentation
at a later date.
this is my silly script:
[script]
#!/bin/ksh -x
# gonna try to create a script
# that gets a list of tables and
# then for each table, get their attributes
datestr=`date +%d%m%y`
workdir=/home/shaunn/temp
tmp1=$workdir/temp1
#remove temp files
if [ -f $tmp1 ];
then
rm -f $tmp1
else
exit 1
fi
#get list of tables and put into tmp1 file
/usr/bin/psql -d bcn -U web -tc "\d" | awk '{print $1}' > $tmp1
for i in `cat $tmp1`
do
/usr/bin/psql -d bcn -U web -tc "\d $i" > $workdir/$i.out
done
[/script]
the lines featuring '/usr/bin/psql' are the ones i
was having an issue with initially. couldn't figure out
the syntax and didn't know, frankly, that i could use
those options.
the second to last line featuring '$workdir/$i.out' is
what gave me multiple files with their own table
attributes instead of outfile.$$ (which only gave
me ONE file with ONE PID attached to it. i was
under the illusion that each time the script read
through the loop, a new file would be created and
affix a new PID. *shrug* don't know why that didn't
happen')
anyhow - that's my story and i'm sticking to it.
-X
shaunnx@my-deja.com (X) wrote in message news:<6375fd1b.0110231150.3a7b0556@posting.google.com>...
Show quoted text
Howdy:
Please redirect me if this is the wrong group. My question
is pretty much SQL related for Postres.I want to write a script (either shell or SQL) to:
1) get a list of tables
2) get the list of attributes, type and modifyer
of each table.It is something in the way of:
for i in `\d`
do
\d $i
doneAs far as I can tell, '\d' describes a table, view or what
have you. '\d' alone gives me a list of tables and views I
have in my database.Any examples out there that does this?
TIA!
-X
I think this passwd through the list several weeks or months ago. It is
a perl script for generating a dia and html file from a PostgreSQL
database.
The HTML layout is a little odd but can be fixed up.
Might offer some interesting options.
Cheers,
Rod
--
Let Accuracy Triumph Over Victory
Zetetic Institute
"David's Sling"
Marc Stiegler