473,387 Members | 1,520 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,387 software developers and data experts.

pl/pgsql trigger table attributes

Hiya,
Not had much experience with tiggers under postgres but am liking them so
far.

My problem is this. I am writing an updates system, postgres holds the
master copy of the database, any changes made to this are logged in an
updates table which is monitored by a daemon, which if any updates are
spotted propigates them to the remote servers.

I have written an initial trigger that spots any changes made to the
tables and creates the correct entries in the updates table, (I even have
the daemon up and running fine too, but thats not the problem :) ).

The way I have written the pl/pgsql function is specific to the specific
table it is attached to, what I would like is a pl/pgsql function which
could be attached to any table to catch the changes. To do this I need to
be able to see what attributes the table that has been modified has, if
the function knows them then this isn't a problem, but requires the
function knows them which I don't want.

Is there a way that a pl/pgsql function can determine the names of the
attributes in a table? or in a record, so that it can pull them out
individually? Or is this something that is not possible. If I can get
the names from the NEW record within the trigger that would be excellent.

The only way I have thought of so far is an additional table which holds
the attribute names for each table being monitored which is used each time
the trigger is fired... I would prefer a less hacky and ikky solution than
this if possible.

Anyone got any suggestions?

Thanks

Graeme Hinchliffe
Nov 23 '05 #1
1 2045
Graeme Hinchliffe <gr***************@zeninternet.co.uk> writes:
The way I have written the pl/pgsql function is specific to the specific
table it is attached to, what I would like is a pl/pgsql function which
could be attached to any table to catch the changes. Is there a way that a pl/pgsql function can determine the names of the
attributes in a table?


This is somewhere between impractical and impossible in plpgsql; that
language is not designed to handle access to fields with
dynamically-determined names and datatypes.

You could probably do it in pltcl, but if I were you I'd skip the PLs
and go straight to coding it in C, because that's likely where you're
going to end up anyway for performance reasons. There are some triggers
in the contrib/ tree that do roughly similar things; perhaps you could
use them as prototypes.

Also consider whether you aren't re-inventing the wheel. It sounds to
me like what you really want is a replication system ... have you looked
at Slony?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Justin | last post by:
I am extremely new at SQL Server2000 and t-sql and I'm looking to create a simple trigger. For explanation sake, let's say I have 3 columns in one table ... Col_1, Col_2 and Col_3. The data type...
0
by: Marko Damaschke | last post by:
Hello alltogether, i'm working on a database-plattform which should work with fail-over-technics. Therefor 2 identic machines with internal RAID are available, which work in...
3
by: D. Stimits | last post by:
I've found a number of basic references for PL/PGSQL, but am looking for something more complete. First question, is there available a *complete* reference for PL/PGSQL? I'm using PostgreSQL...
34
by: Karam Chand | last post by:
Hello I have been working with Access and MySQL for pretty long time. Very simple and able to perform their jobs. I dont need to start a flame anymore :) I have to work with PGSQL for my...
0
by: Bob | last post by:
Hi, I have a very odd postgresql problem. I have some subqueries contained within a function which are looking for unrefernced data and then delete any rows that are found: CREATE OR...
2
by: Gellert, Andre | last post by:
Hello, I have following problem: A user "xy" shouldn't have any rights to a table, but needs data from the content of the table. My idea was to setup a PL/PGSQL procedure to fetch the data...
2
by: Tim Vadnais | last post by:
Hi, My boss wants to add some logging functionality to some of our tables on update/delete/insert. I need to log who, when, table_name, field name, original value and new value for each record,...
2
by: Matt | last post by:
Hi, I'm sure this has been asked before, but my searches haven't come up with an example. I'm writing a generic trigger function called from different tables in plpgsql that needs to get the...
4
by: pravinasp | last post by:
Hello there I have been trying to generate a dynamic querystring thats to be executed inside a trigger function and every time I use NEW.* pl/pgsql throws an error saying 'column * does not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.