Search Postgresql Archives

Re: loading a funtion script from a file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 21, 2007 at 11:10:15AM -0600, Scott Marlowe wrote:
> On Nov 21, 2007 10:49 AM, Richard Huxton <dev@xxxxxxxxxxxx> wrote:
> > Gauthier, Dave wrote:
> > > APparently, from "man psql", -c can do only one thing at a time.  But you could do this with 2-3 commands (or 1 if you want to wrap the 2 up in a shell script or something).  Here's an example...
> > [snip]
> > > psql --dbname mydb -c "\i create_try.sql;"
> > > psql --dbname mydb -c "select trythis('foo');"
> > > psql --dbname mydb -c "drop function trythis(varchar);"
> >
> > Or just put everything in one file and use -f <filename>
> 
> And from the more than one way to skin a cat department:
> 
> cat my.sql | psql mydb
> psql mydb < my.sql

Should anything go wrong with either of these constructs, you don't
get the line number where it did, so the following is better:

psql -1 -f my.sql

This ensures that the entire thing is run in one transaction, and when
anything goes wrong, you'll know the line number where it did.

Transactional DDL invaluable for changing schemas :)

Cheers,
David.
-- 
David Fetter <david@xxxxxxxxxx> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@xxxxxxxxx

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux