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/ ---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match