Re: Ayuda con dblink

From: Miguel Rodríguez Penabad <penabad(at)gmail(dot)com>
To: "Silvana Flores" <sflores(at)cftlotarauco(dot)cl>
Cc: PostgreEs <pgsql-es-ayuda(at)postgresql(dot)org>, "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>
Subject: Re: Ayuda con dblink
Date: 2007-09-12 16:30:13
Message-ID: 95335e4e0709120930i394ce640kaf9e8627323b9e03@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Te mando un ejemplo que a mi me funcionó, para una tabla
creada con
create table t1(a1 int, a2 text);
en la bd 'postgres'

create or replace function inserta(valor text)
returns void language plpgsql as
$body$
begin
PERFORM dblink_exec('hostaddr=127.0.0.1 port=5432 dbname=postgres
user=postgres password=xxxxx',
'insert into t1(a1,a2) values ('
||123
||','''
||valor
||''')' );
end
$body$;

Si usas los "dollar quoted strings"
puedes hacerlo así, sin "escapar" las comillas:

create or replace function inserta2(valor text)
returns void language plpgsql as
$body$
begin
PERFORM dblink_exec('hostaddr=127.0.0.1 port=5432 dbname=postgres
user=postgres password=xxxxxx',
$$insert into t1(a1,a2) values ($$
||123
||$$,'$$
||valor
||$$')$$ );
end
$body$;

saludos

--
Miguel Rodríguez Penabad

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Calabaza Calabaza 2007-09-12 16:42:44 Re: URGENTE; HELP
Previous Message LIZETH ANGHELA SIRPA CACERES 2007-09-12 16:21:50 URGENTE; HELP