I ended up going the pg_catalog route, something like (off the top of
my head without a linux machine by to test it)
output=$(psql -d template1 -t -c "select * from pg_database where
datname='testdb'")
if [ -z "$output" ]; then
psql createdb testdb
else
echo 'the db already exists'
fi
I did the
> In my original email i forgot to mentioned i need to know if the
> database exists or not from the shell script. If it doesn't exist i
> would then create it. Currently i was just creating the db everytime
> our db script is run (since it doesn't hurt the db) but this generates
> the 'db alread
On Fri, 2006-10-27 at 10:12, Jon Horsman wrote:
> In my original email i forgot to mentioned i need to know if the
> database exists or not from the shell script. If it doesn't exist i
> would then create it. Currently i was just creating the db everytime
> our db script is run (since it doesn't
simplest might be psql -l.
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Jon Horsman
> Sent: Friday, October 27, 2006 8:13 AM
> To: pgsql-sql@postgresql.org
> Subject: Re: [SQL] How to query information schema from shell
For more information, i know how this is done using the pg_catalog but
have yet to find out how its done with the information schema.
select * from pg_catalog.pg_database where datname='test'
will work for me but i can't find a solution with the IS. I'd prefer
to use the IS if its as easily don
In my original email i forgot to mentioned i need to know if the
database exists or not from the shell script. If it doesn't exist i
would then create it. Currently i was just creating the db everytime
our db script is run (since it doesn't hurt the db) but this generates
the 'db already exists'
Thanks for the suggestions guys, i'll give this a try.
Jon
---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings
You can use "-c" option of psql client. Ex.: psql -p 5000 -d database -c "SELECT * FROM information_schema.tables WHERE table_schema = 'public'"
2006/10/27, Jon Horsman <[EMAIL PROTECTED]>:
Hey,I'm trying to figure out how i can query the postgres informationschema from a bourne shell
am Fri, dem 27.10.2006, um 9:31:03 -0400 mailte Jon Horsman folgendes:
> Hey,
>
> I'm trying to figure out how i can query the postgres information
> schema from a bourne shell script on linux. I need to know if a
> user/table exists. Does someone mind giving me a quick example of how
You can
> I'm trying to figure out how i can query the postgres information
> schema from a bourne shell script on linux. I need to know if a
> user/table exists. Does someone mind giving me a quick example of how
> this works, is this possible?
% for tn in `psql -Umnp -dmnp_gp -hstgdb0 -tA -c"select ta
Hey,
I'm trying to figure out how i can query the postgres information
schema from a bourne shell script on linux. I need to know if a
user/table exists. Does someone mind giving me a quick example of how
this works, is this possible?
Thanks,
Jon.
---(end of broadcast
11 matches
Mail list logo