Re: multiple psql commands in batch

From: "Daniel T(dot) Staal" <DStaal(at)usa(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: multiple psql commands in batch
Date: 2006-06-02 18:41:13
Message-ID: 54994.63.172.115.138.1149273673.squirrel@MageHandbook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, June 2, 2006 2:28 pm, Tobias Boes said:
> G'Day all,
>
> i know that this issues was discussed multiple time, but i still stuck in
> processing multiple pgsql commands in a DOS batch file.
> I want to create a user, than a database with the following command:
> C:\financial-planner\pgsql\bin\psql.exe -U postgres <
> create_user_and_db.sql
>
> this scceeds. in the create_user_and_db.sql I stored the SQL-commands to
> setup the database and the database user.
> but afterwards I want to switch to "mydatabase" and process the create
> table statements. In the pgsql shell I can switch to "mydatabase" with the
> following command:
> \c mydatabase
> but how can I run mulitple pgsql commands in a batch job? After loads of
> reading I'm still not able to do this.
> Any help is really appreciated!
> Thanks,
> Tobias

The switch you are looking for is '-d'. Use like such:
C:\financial-planner\pgsql\bin\psql.exe -d mydatabase

(With appropriate user and commands, of course.)

I'd move the create table statements to a seperate file, and make another
call from the batch file.

(Otherwise, in this context I believe schema == database, so if you
appended the database name to table names in the SQL creates like this
'mydatabase.mytable' that should work as well.)

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author. Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes. This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2006-06-02 19:19:16 Re: Locale and Initdb Errors
Previous Message Tobias Boes 2006-06-02 18:28:18 multiple psql commands in batch