473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to make cross-database reference in Postgres

Hello,
We have two postgres databases running in the same server. Now we have to write a trigger in one database to access a table in another database for live data updation in both databases. How can we perform that?
Can we use contrib/dblink? If we yes how to do that? Our postgres version is 7.4.7. And the function dblink does not exist.How to do that?
Or is there a better way of doing this cross reference.

-Krithika.
Dec 28 '06 #1
3 16144
michaelb
534 Expert 512MB
For installation look at contrib/dblink/README.dblink
If you don't have a source code you can download it from http://www.postgresql.org

I don't know if this would work for you, often things you can do from inside a trigger, or a function have certain limitations.
Dec 29 '06 #2
I installed the postgresql-contrib package as it was available with my debian sarge 3.1 .
Then i just did
psql dbname < /usr/share/postgres/contrib/dblink.sql

I did some select operations using dblink and they worked perfectly.
When i tried to write a trigger in pl/pgsql like this ,

CREATE TRIGGER triggername BEFORE INSERT OR UPDATE ON testtable
FOR EACH ROW EXECUTE PROCEDURE test();

CREATE OR REPLACE FUNCTION test() RETURNS TRIGGER AS '
BEGIN
SELECT dblink_exec(''dbname=sample'',''insert into testtable values (NEW.x,NEW.y)'');
END;
' LANGUAGE plpgsql;

It threw an error like this,
ERROR: sql error
DETAIL: ERROR: NEW used in query that is not in a rule

Actually i want to insert the records that are getting inserted into testtable in my current db , also into a table testtable in another db 'sample' simultaneously. Is this the right way of doing this using dblink ?
Jan 3 '07 #3
anvesh
2
DbLink extension of PostgreSQL which is used to connect one database to another database.
I have prepared full demonstration on this. Also provide full script with example.
You must visit this post:
Aug 22 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: jonjon | last post by:
Hi, I want to be able to define the right property of my absolute positionned elements... for example if a button is 50px left and 150px right, it will resize when the page is resized. This is...
3
by: rollasoc | last post by:
Hi, Doing a bit of system testing on a Windows 98 laptop. (.Net 1.1 app). Did a bit of testing. Loaded a previously saved file. A gray box appeared with the text and buttons all white...
23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
6
by: Sergey Poberezovskiy | last post by:
Hi, What do I need to type in the advanced options of the New Question dialog of this newsgroup to cross-post, say to VB.Net General Discussion. I have attempted a few different options, but...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
48
by: Nathan Sokalski | last post by:
Ever since I found out that they didn't give us a way to install both IE6 and IE7 on the same machine, I have been more frustrated and annoyed with Microsoft than I ever have been with any company...
2
by: JDeats | last post by:
>From my development envrionment (i.e. a single WinXP notebook PC) I have a basic AJAX application that is making the call to a Windows Form page that just returns the request back to the AJAX...
11
by: Simon van Beek | last post by:
Dear reader, By opening an application I get always the main Access window with the closing cross in the above right corner. Is there a possibility to make this closing cross invisible? ...
6
by: ampo | last post by:
Hello. Can anyone help with cross-domain problem? I have HTML page from server1 that send xmlHTTPRequest to server2. How can I do it? Thanks.
1
by: NeophyteDK | last post by:
hello Im trying to cross compile php for powerpc on Win XP with MinGW. I have succesfully cc'ed Lighttpd, with the same toochain. i use the command line: CC=powerpc-linux-gcc AR=powerpc-linux-ar...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.