Re: Insert psql commands inside a script

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Insert psql commands inside a script
Дата
Msg-id 20050423055055.GB96734@winnie.fuhr.org
обсуждение исходный текст
Ответ на Insert psql commands inside a script  ("Letnes, David G." <david.letnes@unisys.com>)
Список pgsql-sql
On Thu, Apr 21, 2005 at 05:19:23PM -0500, Letnes, David G. wrote:
> 
>   I have used the psql -f /tmp/SelectCommands.sql before, but now I want
> to put the sql statement right in the shell script.  I haven't had any
> luck.  Is there a command I can use that will not point to a file for
> the sql instructions but right on the same line.  I use very short psql
> commands and would like to do it all with 1 file.

For simple queries you can use psql -c:
 psql -c 'SELECT * FROM foo'

You can embed an SQL script with a "here document" if your shell
supports it (it probably does):
 #!/bin/sh  echo "before database connection"  psql <<END_OF_SQL CREATE TABLE foo (x integer); INSERT INTO foo VALUES
(42);SELECT * FROM foo; DROP TABLE foo; END_OF_SQL  echo "after database connection"
 

See your shell's documentation for details.  See also the psql
documentation for its options and ways to control its output.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


В списке pgsql-sql по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: Coming from Oracle SQL
Следующее
От: Andreas Kretschmer
Дата:
Сообщение: Re: [despammed] Insert psql commands inside a script