Insert psql commands inside a script
Insert psql commands inside a script
От:
"Letnes, David G." <david.letnes@unisys.com>
Дата:
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.
Thank You
David
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Re: Insert psql commands inside a script
От:
Michael Fuhr <mike@fuhr.org>
Дата:
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 <
Re: [despammed] Insert psql commands inside a script
От:
Andreas Kretschmer <akretschmer@despammed.com>
Дата:
am 21.04.2005, um 17:19:23 -0500 mailte Letnes, David G. folgendes: > > 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. echo "select bla from fasel" | psql -U database You can also use here documents, shell-variables and so on. Regards, Andreas -- Andreas Kretschmer (Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net=== Schollglas Unternehmensgruppe ===
Re: [despammed] Insert psql commands inside a script
От:
Geoffrey <esoteric@3times25.net>
Дата:
Andreas Kretschmer wrote: > am 21.04.2005, um 17:19:23 -0500 mailte Letnes, David G. folgendes: > >> 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. > > > echo "select bla from fasel" | psql -U database > > You can also use here documents, shell-variables and so on. Or you can do the following: psql database < sqlcode where sqlcode contains your sql. -- Until later, Geoffrey
Re: [despammed] Insert psql commands inside a script
От:
Michael Fuhr <mike@fuhr.org>
Дата:
On Sat, Apr 23, 2005 at 08:15:48AM -0400, Geoffrey wrote: > > Or you can do the following: > > psql database < sqlcode > > where sqlcode contains your sql. That command redirects the standard input from the file named sqlcode; the requirement says NOT to use an external file. -- Michael Fuhr http://www.fuhr.org/~mfuhr/
Re: [despammed] Insert psql commands inside a script
От:
Geoffrey <esoteric@3times25.net>
Дата:
Michael Fuhr wrote: > On Sat, Apr 23, 2005 at 08:15:48AM -0400, Geoffrey wrote: > >>Or you can do the following: >> >>psql database < sqlcode >> >>where sqlcode contains your sql. > > > That command redirects the standard input from the file named > sqlcode; the requirement says NOT to use an external file. My bad, I misread the post as indicating he wanted to use an external file. Too early on a Saturday with a late Friday and not enough coffee yet... -- Until later, Geoffrey