dbTalk Databases Forums  

Executing sql script

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Executing sql script in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Loftis, Charles E
 
Posts: n/a

Default Executing sql script - 06-03-2004 , 02:23 PM






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 (AT) postgresql (DOT) org)


Reply With Quote
  #2  
Old   
Bryan Irvine
 
Posts: n/a

Default Re: Executing sql script - 06-03-2004 , 02:44 PM






cat foo | psql bar

or

pgsql>\i /somedir/foo


--Bryan

On Thu, 2004-06-03 at 12:23, Loftis, Charles E wrote:
Quote:
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 (AT) postgresql (DOT) org)

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
  #3  
Old   
Joe Erickson
 
Posts: n/a

Default Re: Executing sql script - 06-03-2004 , 02:45 PM



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 the server 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 (AT) postgresql (DOT) org
[mailtogsql-novice-owner (AT) postgresql (DOT) org]On Behalf Of Loftis, Charles E
Sent: Thursday, June 03, 2004 3:24 PM
To: pgsql-novice (AT) postgresql (DOT) 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 (AT) postgresql (DOT) org)

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Reply With Quote
  #4  
Old   
Frank Bax
 
Posts: n/a

Default Re: Executing sql script - 06-03-2004 , 02:45 PM



At 03:23 PM 6/3/04, Loftis, Charles E wrote:
Quote:
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



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
  #5  
Old   
Joe Erickson
 
Posts: n/a

Default Re: Executing sql script - 06-03-2004 , 02:47 PM



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 (AT) postgresql (DOT) org
[mailtogsql-novice-owner (AT) postgresql (DOT) org]On Behalf Of Loftis, Charles E
Sent: Thursday, June 03, 2004 3:24 PM
To: pgsql-novice (AT) postgresql (DOT) 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 (AT) postgresql (DOT) org)

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
  #6  
Old   
Frank Bax
 
Posts: n/a

Default Re: Executing sql script - 06-03-2004 , 03:31 PM



At 03:45 PM 6/3/04, Joe Erickson wrote:
Quote:
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



Reply With Quote
  #7  
Old   
Joe Erickson
 
Posts: n/a

Default Re: Executing sql script - 06-03-2004 , 03:58 PM



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 (AT) postgresql (DOT) org
[mailtogsql-novice-owner (AT) postgresql (DOT) org]On Behalf Of Frank Bax
Sent: Thursday, June 03, 2004 4:32 PM
To: pgsql-novice (AT) postgresql (DOT) org
Subject: Re: [NOVICE] Executing sql script


At 03:45 PM 6/3/04, Joe Erickson wrote:
Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.