Re: loading a funtion script from a file - Mailing list pgsql-general

From Gauthier, Dave
Subject Re: loading a funtion script from a file
Date
Msg-id D7FF158337303A419CF4A183F48302D6035EAC83@hdsmsx411.amr.corp.intel.com
Whole thread Raw
In response to Re: loading a funtion script from a file  (Andreas Kretschmer <akretschmer@spamfence.net>)
Responses Re: loading a funtion script from a file  (Richard Huxton <dev@archonet.com>)
List pgsql-general

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

The text file that creates the script....

create or replace function trythis(varchar) returns varchar as $$

declare aname varchar(128);

begin

  select name into aname from templates limit 1;

  if not found then raise notice 'nuthin found'; end if;

  aname := aname||'---'||$1;

  return aname;

end;

$$ language plpgsql;

How to run it...

psql --dbname mydb -c "\i create_try.sql;"

psql --dbname mydb -c "select trythis('foo');"

psql --dbname mydb -c "drop function trythis(varchar);"

-dave



-----Original Message-----
From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Andreas Kretschmer
Sent: Wednesday, November 21, 2007 10:50 AM
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] loading a funtion script from a file

Pau Marc Munoz Torres <paumarc@gmail.com> schrieb:

> Hi

>

>  I've written a sql function in a text file, and now, i would like to upload

> into postgresql an execute, is there any command to do it? as far as I know in

> mysql exist source command, is there something similar in postgresql?

Of course. Start psql and type:

\i /path/to/your/script.sql

Regards, Andreas

--

Really, I'm not out to destroy Microsoft. That will just be a completely

unintentional side effect.                              (Linus Torvalds)

"If I was god, I would recompile penguin with --enable-fly."    (unknow)

Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

---------------------------(end of broadcast)---------------------------

TIP 5: don't forget to increase your free space map settings

pgsql-general by date:

Previous
From: Erik Jones
Date:
Subject: Re: Postgres table size
Next
From: Erik Jones
Date:
Subject: Re: Dynamic expressions set in "order by" clause