Thread: Executing sql script

Executing sql script

From
"Loftis, Charles E"
Date:
I want to execute the sql stored in a directory on my system.

How do I submit this file, in batch, to pgsql to be executed?



Re: Executing sql script

From
"Joe Erickson"
Date:
Just put it on the command line after psql:

psql example.sql

psql will take the file and run each line to the server.

If the server is not on your computer, you will need to specify the hostname to the computer and a username to log into
theserver with: 

psql -h server.postgres.com -U dba example.sql

To send multiple files, just list them all:

psql example1.sql example2.sql example3.sql

or

psql example*


Run psql --help for more options.

-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Loftis, Charles E
Sent: Thursday, June 03, 2004 3:24 PM
To: pgsql-novice@postgresql.org
Subject: [NOVICE] Executing sql script


I want to execute the sql stored in a directory on my system.

How do I submit this file, in batch, to pgsql to be executed?



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Re: Executing sql script

From
Bryan Irvine
Date:
cat foo | psql bar

or

pgsql>\i /somedir/foo


--Bryan

On Thu, 2004-06-03 at 12:23, Loftis, Charles E wrote:
> I want to execute the sql stored in a directory on my system.
>
> How do I submit this file, in batch, to pgsql to be executed?
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)


Re: Executing sql script

From
"Joe Erickson"
Date:
Ahh!!  I'm an idiot.

Put -f before the filenames in the command line:

psql -f example.sql

Sorry.



-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Loftis, Charles E
Sent: Thursday, June 03, 2004 3:24 PM
To: pgsql-novice@postgresql.org
Subject: [NOVICE] Executing sql script


I want to execute the sql stored in a directory on my system.

How do I submit this file, in batch, to pgsql to be executed?



---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Re: Executing sql script

From
Frank Bax
Date:
At 03:23 PM 6/3/04, Loftis, Charles E wrote:
>I want to execute the sql stored in a directory on my system.
>How do I submit this file, in batch, to pgsql to be executed?


If your file is script.sql, then:
         psql < script.sql



Re: Executing sql script

From
Frank Bax
Date:
At 03:45 PM 6/3/04, Joe Erickson wrote:
>To send multiple files, just list them all:
>
>psql example1.sql example2.sql example3.sql
>
>or
>
>psql example*


Is there any guarantee of sequence with either of these?


Re: Executing sql script

From
"Joe Erickson"
Date:
Again, I am an idiot.  At the time I wrote that, I was thinking of Sybase.  PostgreSQL can not do this.

However, in a good shell you can get something like this to work.  For instance:

foreach file (example*)
psql $file
end

Shells will put them through in alpha order.

BTW, I use tcsh.


-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Frank Bax
Sent: Thursday, June 03, 2004 4:32 PM
To: pgsql-novice@postgresql.org
Subject: Re: [NOVICE] Executing sql script


At 03:45 PM 6/3/04, Joe Erickson wrote:
>To send multiple files, just list them all:
>
>psql example1.sql example2.sql example3.sql
>
>or
>
>psql example*


Is there any guarantee of sequence with either of these?


---------------------------(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