Обсуждение: using external .sql files from shell script ?
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