using external .sql files from shell script ? - Mailing list pgsql-novice

From Francois PUSSAULT
Subject using external .sql files from shell script ?
Date
Msg-id OFE55DBE39.3CA944D6-ONC1256E24.0037A71B-41256E24.00372FC3@atofina.com
Whole thread Raw
List pgsql-novice

Hello all

#> I hope you can help me. I am a novice to postgreSQL.

#> I'm tying to write a little shellscript/SQL application on unix system.

#> I use a simple shell script that calls some external SQL insructions file.


#> so I have 2 questions about it
--------------------------------

1) Is there any oracle-SPOOL similar command under psql ?

#> actually I use psql -f foobar.sql


--------------------------------

2) How to use shell scripts variables as parameter to the external .sql file ?


#> for example currently I must do :


#!/bin/sh

.....

.....

read toto

.....

psql -f $commande.sql $basename -o $commande.log

.....

exit


#> all my .sql files look like :

.....

\set foo '\''`echo $toto`'\''

\set tabl '\''`echo $table`'\''

.....

begin

.....

insert into :tabl values(....,....,....,:foo,....);

.....

end


#> So is this possible to use toto named variable from shell script without creating foo named variable in .sql script ?

#> Is there a better method to do so ?


-----------------------------

regards

pgsql-novice by date:

Previous
From: Christian Poecher
Date:
Subject: Problem with initdb. Locale?
Next
From: Aarni Ruuhimäki
Date:
Subject: 7.4.1 template1