Re: creating a trigger to access another postgres database?

From: carty mc <cartymc3(at)yahoo(dot)com>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: creating a trigger to access another postgres database?
Date: 2008-03-29 14:01:17
Message-ID: 856591.17020.qm@web58502.mail.re3.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you very much Richard. It worked like a charm.
I Appreciate your help

Richard Huxton <dev(at)archonet(dot)com> wrote:
carty mc wrote:
> Thanks Richard, I went through dblink and tried it . But I am not
> able to pass variables to sql stmt of dblink_exec function .
> Basically If I hardcode the values for updating a table for the sql
> statement in different database it is working fine. But What I wanted
> to do is get the info from existing modified row and pass that into
> the update query which I am writing inside dblink_exec call.
>
> my sql inside dblink_exec call would look like UPDATE my_table set
> myotherDBTableField = NEW.currDBTableField WHERE {condition}

dblink takes SQL as text - it's really just another external client as
far as the other database is concerned. You'll want to build your
query-string as a string:

mySql := 'UPDATE mytable SET f = ' || quote_literal(NEW.f) || ' WHERE ...'
dblink(connstr, mySql);

Don't forget to consider how NULLs will affect the query-string. See the
string-functions section of the manuals for quote_literal/quote_ident.

--
Richard Huxton
Archonet Ltd


---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2008-03-29 14:17:41 Re: Using tables in other PostGreSQL database
Previous Message Peter Eisentraut 2008-03-29 13:44:55 Re: Survey: renaming/removing script binaries (createdb, createuser...)