From: | "Robert B(dot) Easter" <reaster(at)comptechnews(dot)com> |
---|---|
To: | "pblunat" <pblunat(at)ujf-grenoble(dot)fr>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Execute a string of command in sql'script |
Date: | 2001-01-19 19:12:51 |
Message-ID: | 0101191412510P.02219@comptechnews |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
In 7.1, PL/pgSQL has an "EXECUTE <query-string>" statement that can execute
dynamically created query strings. See the development docs at
postgresql.org.
On Friday 19 January 2001 11:54, pblunat wrote:
> Hi all,
> I'm using PostgreSQL 7.0.2 on RedHat 6.0.
>
> I compose a SQL command string with function below :
>
>
> CREATE FUNCTION bdrm_copy(text, text) RETURNS text AS '
>
> DECLARE
> baseact ALIAS FOR $1;
> namefich ALIAS FOR $2;
> path0 TEXT;
> path1 TEXT;
> path2 TEXT;
> path3 TEXT;
> BEGIN
> SELECT INTO path0 CAST(ig_tempo AS TEXT)
> FROM ti_bdrm
> WHERE ig_base = baseact;
> path0 := trim(path0) || trim(namefich);
> path1 := ''COPY ttx_window7 TO \'\''';
> path2 := path1 || path0;
> path3 := ''\'\''';
> path0 := path2 || path3 || '';'';
> RETURN path0 ;
> END;'
> LANGUAGE 'plpgsql';
>
>
> the result of :
>
> SELECT bdrm_copy('MOHO99', 'test2.txt') AS my_command_string;
>
> is :
>
> my_command_string
> -----------------------------------------------
> COPY ttx_window7 TO '/db/bdrm/out/test2.txt';
>
>
> Is it possible to execute this line of command? More generally, can one
> execute the contents of a variable or a field in postgresql' script?
>
> Thanks ;)-
--
-------- Robert B. Easter reaster(at)comptechnews(dot)com ---------
-- CompTechNews Message Board http://www.comptechnews.com/ --
-- CompTechServ Tech Services http://www.comptechserv.com/ --
---------- http://www.comptechnews.com/~reaster/ ------------
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 2001-01-19 19:32:07 | Re: Re: initdb doesn not create template1 database |
Previous Message | Timothy H. Keitt | 2001-01-19 18:49:16 | lo_cat function? |