473,653 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need simple strategy for universal extension table

Instead of putting the same 12 columns on every table (these 12 columns
contain info about who created the record and when, for example)... It may
be more efficient to make a new table to hold that data.

This new table would act as a universal extension table. Instead of having
FKs back to any particular table, it would contain regular keys that point
back to whatever table::record is its source.

I was thinking of using two keys only:

xmOwnerInfo
COL1 PK* oidParentTable
COL2 PK* oidParentTables Record
COL3-15 [attribs]

Thoughts?

--
TJ Talluto
torpedo51 at yahoo dot com
Nov 23 '05 #1
2 3036
Since nobody has mentioned any nuances about mapping these keys to system
tables in this particular database, I'll assume this is a good idea for
now.

--
TJ Talluto
torpedo51 at yahoo dot com
Nov 23 '05 #2
On Tue, 09 Nov 2004 19:20:20 GMT, TJ Talluto <tj@getlostspam mers.com> wrote:
This new table would act as a universal extension table. Instead of having
FKs back to any particular table, it would contain regular keys that point
back to whatever table::record is its source.

I was thinking of using two keys only:

xmOwnerInfo
COL1 PK* oidParentTable
COL2 PK* oidParentTables Record
COL3-15 [attribs]


I am doing something similar to this, though at this point I'm not
using it for storing creator/updator fields. I need to be able to
group any arbitrary set of rows from multiple tables together and
apply sets of attributes to them. I have a central 'entity' table
that holds the table name and the value of the 'id' column from that
table. Then I attach two triggers to each table whos rows I want to
track. I am using tablename and a BIGSERIAL 'id' column because OIDs
on tables

1) are only a 32 bit INT and I may very well wrap around on them,
whereas a BIGSERIAL is a 64 bit INT and

2) the fact that OIDs may go away in a future version of PG.

Here's exactly what I'm doing (NOTE: this is for 8.0beta, so you will
have to adjust the quoting on the trigger functions for 7.x):

CREATE SCHEMA func;
CREATE SCHEMA entity;

CREATE TABLE entity.authorit y_list (
id BIGSERIAL PRIMARY KEY,
entity BIGINT,
entity_type text
) WITHOUT OIDS;

CREATE FUNCTION func.add_entity _entry () RETURNS TRIGGER AS $func$
BEGIN
INSERT INTO entity.authorit y_list (entity,entity_ type)
VALUES (NEW.id,TG_ARGV[0] || '.' || TG_RELNAME);
RETURN NEW;
END;
$func$ LANGUAGE 'plpgsql';

CREATE FUNCTION func.remove_ent ity_entry () RETURNS TRIGGER AS $func$
BEGIN
DELETE FROM entity.authorit y_list
WHERE entity = OLD.id AND
entity_type = TG_ARGV[0] || '.' || TG_RELNAME;
RETURN OLD;
END;
$func$ LANGUAGE 'plpgsql';

CREATE TABLE someschema.some table ( id BIGSERIAL, name TEXT );

CREATE TRIGGER sometable_add_e ntity_trig
AFTER INSERT ON someschema.some table
FOR EACH ROW
EXECUTE PROCEDURE func.add_entity _entry(somesche ma);

CREATE TRIGGER sometable_remov e_entity_trig
BEFORE DELETE ON someschema.some table
FOR EACH ROW
EXECUTE PROCEDURE func.remove_ent ity_entry(somes chema);
I am supplying the schema name to the trigger because the relation
name passed in as TG_RELNAME is the schema unqualified table name and
I have the same table name in several schemas.

Any comments on any of this would be very welcome.

--
Mike Rylander
mr*******@gmail .com
GPLS -- PINES Development
Database Developer

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #3

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

Similar topics

0
540
by: Robert Oschler | last post by:
I want to have a master table and a detail table. I want the master table record to be created only if one does not exist already for a given account ID. Here is my concern: Let's say I have several different web pages being viewed by several different web surfers. The viewing of the web pages triggers the same PHP code that attempts to locate a desired master record, auto-creating it if it does not exists.
7
1910
by: Riley DeWiley | last post by:
I am continually amazed by SQL's ability to humble me .... I have a toy query into a toy database that looks just like this: SELECT . FROM f, fw, w WHERE f.id = fw.fid and fw.wid = w.id and w.id in (((((select distinct w.id from w where w.x in ('a', 'b') ))))) GROUP BY . HAVING count(f.id) = (select count(id) from (((((select distinct w.id from w
23
2585
by: Adam | last post by:
I am coding a microkernel based off of Tanebaum's theroy. For Isis to be extensible, fast, and secure, it has been decided it will be a microkernel. Not in the old Mach sense of the word, but in the size of the entire project. It is a microkernel, that will limit interprocess communication. But as Tanenbaum says, you learn nothing by reading theroy alone. The code should be self-explaintory. Another reason I choose the microkernel method...
8
5104
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value types or std::vector<int>. So where I would use an int* and reallocate it from time to time in C, and randomly access it via , then I figure to copy the capacity and reserve methods, because I just need a growable array. I get to considering...
0
1154
by: cyprian.pl | last post by:
Hello, I would like to ask some opinions on the best DB strategy for the following problem: I have a table containing information about artists (names, dates, descriptions in three languages etc). The full-text index is put on 16 fields. A user can select records to have access to (like favorite artists). There are two possible full-text searches: through the whole table and only within user's records.
15
4596
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
6
2763
by: Hemant Shah | last post by:
Folks, I am having trouble with a query. DB2 does not use index, it does relation scan of the table. I am running DB2 UDB 8.2 on Fedora Core release 4 (Stentz) # db2level DB21085I Instance "dbap68" uses "32" bits and DB2 code release "SQL08015" with level identifier "02060106".
25
3104
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of course then the file doesn't get seen by the user. Is there any command that essentially executes the code and then echo's it? something that will take a string like '<body>blah<?php echo 'Hello'; ?></body>' and actually interpret the php
14
1657
by: Robin Becker | last post by:
A user reports problems with one of our extensions when running the intel compiled extension on ppc and vice versa. He is building the extension as a universal binary. Although the intel compiled version runs fine it displays a known bug when run on a ppc. It appears we have an endianness dependency which is statically compiled into the binaries. One proposed fix is to make the endian variable code dynamically change at run time. ...
0
8370
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8704
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8590
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.