executar função em variável/inserir variável no INSERT

PostgreSQL

18/06/2008

Bom dia,

estou com um problema para inserir uma variável no comando insert...

a_output := insert into aller(the_geom) values ((SELECT the_geom FROM trecho_edges  WHERE edge_id IN (SELECT edge_id FROM shortest_path_astar(´SELECT  id,source,target,cost,reverse_cost, x1,y1,x2,y2 FROM trecho_edges´,v1,v2,false,true));


A função não reconhece v1 e v2, então tentei armazenar tudo em uma variável fazendo o código abaixo:

create or replace function testestring () returns text as $body$

declare

a_output varchar(1000);
b_output varchar(1000);
c_output varchar(1000);
d_output text;
v1integer;
v2integer;

begin

select into v1 (select edge_id from trecho where nmvia = ´AV.SETE DE SETEMBRO´ and noinicio <= ´04000´ and nofim >= ´04000´);
select into v2 (select edge_id from trecho where nmvia = ´R.VERONICA TRIBEK MORO´ and noinicio <= ´00566´ and nofim >= ´00566´);

a_output := $a$insert into aller(the_geom) values ((SELECT the_geom FROM trecho_edges  WHERE edge_id IN (SELECT edge_id FROM shortest_path_astar(´SELECT  id,source,target,cost,reverse_cost, x1,y1,x2,y2 FROM trecho_edges´,$a$;
b_output := $b$,$b$;
c_output := $c$,false,true));$c$;

d_output = a_output || v1 || b_output || v2 || c_output;
execute d_output;
return d_output;

end;

$body$ language plpgsql;


Se eu não executo d_output ele me retorna o comando com o valor das variáveis alocadas corretamente:

"insert into aller(the_geom) values ((SELECT the_geom FROM trecho_edges  WHERE edge_id IN (SELECT edge_id FROM shortest_path_astar(´SELECT  id,source,target,cost,reverse_cost, x1,y1,x2,y2 FROM trecho_edges´,265,247,false,true));"


No entanto se eu executar d_output
ERROR: syntax error at or near ";"
SQL state: 42601
Context: PL/pgSQL function "testestring" line 21 at execute statement


já tentei retirar o ponto e vírgula do c_output, mas obtenho:

ERROR: syntax error at end of input
SQL state: 42601


Sou estudante de eng. Cartográfica, só estou mexendo com isso por causa do meu projeto final (eu sei, nunca mais mexo com isso =))
Já procurei em todos os cantos da internet e não consegui resolver, já troquei por ´´ ´ ´´ mas não deu certo.

Agradeço desde já.

Jefferson


Jeffferrson

Jeffferrson

Curtidas 0

Respostas

Jeffferrson

Jeffferrson

18/06/2008

desculpem, mas eu não estava colocando o número correto de parênteses no final... =(

n vi onde eu apago o tópico...

obrigado


GOSTEI 0
POSTAR