Re: loading a funtion script from a file

From: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
To: "Andreas Kretschmer" <akretschmer(at)spamfence(dot)net>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: loading a funtion script from a file
Date: 2007-11-21 16:41:25
Message-ID: D7FF158337303A419CF4A183F48302D6035EAC83@hdsmsx411.amr.corp.intel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Andreas Kretschmer
Sent: Wednesday, November 21, 2007 10:50 AM
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] loading a funtion script from a file

Pau Marc Munoz Torres <paumarc(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Erik Jones 2007-11-21 16:43:37 Re: Dynamic expressions set in "order by" clause
Previous Message Erik Jones 2007-11-21 16:38:44 Re: Postgres table size