X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 566CD53486 for ; Sat, 23 Apr 2005 02:51:09 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26513-01 for ; Sat, 23 Apr 2005 05:50:59 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id E74D353327 for ; Sat, 23 Apr 2005 02:50:58 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j3N5ou0r035971 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Apr 2005 23:50:58 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j3N5ouKi096872; Fri, 22 Apr 2005 23:50:56 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j3N5otZK096871; Fri, 22 Apr 2005 23:50:55 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 22 Apr 2005 23:50:55 -0600 From: Michael Fuhr To: "Letnes, David G." Cc: pgsql-sql@postgresql.org Subject: Re: Insert psql commands inside a script Message-ID: <20050423055055.GB96734@winnie.fuhr.org> References: <2F1DE8CC97C00645B9FEA539982DA22401900D5A@USEA-EXCH4.na.uis.unisys.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2F1DE8CC97C00645B9FEA539982DA22401900D5A@USEA-EXCH4.na.uis.unisys.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/353 X-Sequence-Number: 21246 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 <