RESOLVED : Re: sql script questions - Mailing list pgsql-general

From shaunnx@my-deja.com (X)
Subject RESOLVED : Re: sql script questions
Date
Msg-id 6375fd1b.0110241247.7095ff89@posting.google.com
Whole thread Raw
In response to sql script questions  (shaunnx@my-deja.com (X))
Responses Re: RESOLVED : Re: sql script questions
List pgsql-general
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>...
> 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

pgsql-general by date:

Previous
From: Paul Green
Date:
Subject: Using other database tables in a query
Next
From: Markus Wagner
Date:
Subject: optimizing record matching