Search Postgresql Archives

Re: loading a funtion script from a file

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

 



Title: RE: loading a funtion script from a file

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@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of Andreas Kretschmer
Sent: Wednesday, November 21, 2007 10:50 AM
To: pgsql-general@xxxxxxxxxxxxxx
Subject: Re: loading a funtion script from a file

Pau Marc Munoz Torres <paumarc@xxxxxxxxx> 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


[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