473,657 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

returning inserted rows, derived tables design

Hello again,

as I am new to PostgreSQL (great pice of softwork btw) this probably won't
be the last question.

I access PostgreSQL from Java via the PostgreSQL JDBC driver. I am
currently building a little framework that provides basic CRUD
operations by mapping class properties to database columns. All my
primary keys are artificial and built by sequences (datat type bigserial).
Now I need to (re-)read the row that was inserted/updated because triggers
may have changed the column values, row versions (CMAX, thanks to Tom Lane)
are different and so on.
For the update operation I "know" wich row to select since the primary key
alread exists. But what about the insert? When I know the sequence for
a particular primary key I could obtain its last value select the row
with this very primary key...
This would imply that my framework must "know" wich sequence belongs to
a primary key. I don't like this idea.
To come to an end, a RETURNNG clause for the insert/update statement would
be the perfect solution, but there isn't any, right?

Another uncertainty: Is it wise to have most tables derive from one base
table (concering performace, concurrence, maintainability , etc). Let's say
99% of my tables have an Id (artificial primary key), CreatedBy, UpdatedBy
column.
Should I put those columns in a base table and derive from it or let each
table have these columns by itself.
As for the Id column (bigserial) in the "derived solution" there would be
only one sequence wich makes it unique for the whole database. That sounds
very appealing from the application point of view.

Thanks for your patience
Ruediger

--
+++ GMX DSL Premiumtarife 3 Monate gratis* + WLAN-Router 0,- EUR* +++
Clevere DSL-Nutzer wechseln jetzt zu GMX: http://www.gmx.net/de/go/dsl
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #1
1 2590
On Sat, Oct 23, 2004 at 12:30:07 +0200,
Ruediger Herrmann <ru************ ***@gmx.de> wrote:
Hello again,

as I am new to PostgreSQL (great pice of softwork btw) this probably won't
be the last question.

I access PostgreSQL from Java via the PostgreSQL JDBC driver. I am
currently building a little framework that provides basic CRUD
operations by mapping class properties to database columns. All my
primary keys are artificial and built by sequences (datat type bigserial).
Now I need to (re-)read the row that was inserted/updated because triggers
may have changed the column values, row versions (CMAX, thanks to Tom Lane)
are different and so on.
For the update operation I "know" wich row to select since the primary key
alread exists. But what about the insert? When I know the sequence for
a particular primary key I could obtain its last value select the row
with this very primary key...
This would imply that my framework must "know" wich sequence belongs to
a primary key. I don't like this idea.
To come to an end, a RETURNNG clause for the insert/update statement would
be the perfect solution, but there isn't any, right?
Currently the sequence names can be derived from the table and serial
column names. If the names aren't too long, I think it is
tablename_seria lname_seq. In 8.0 (unreleased) there is a function that returns
the name of the sequence associated with a serial column.
Another uncertainty: Is it wise to have most tables derive from one base
table (concering performace, concurrence, maintainability , etc). Let's say
99% of my tables have an Id (artificial primary key), CreatedBy, UpdatedBy
column.
Should I put those columns in a base table and derive from it or let each
table have these columns by itself.
As for the Id column (bigserial) in the "derived solution" there would be
only one sequence wich makes it unique for the whole database. That sounds
very appealing from the application point of view.


I would avoid using inheritance and use views instead. Inheritance is currently
half-baked and you have to do too much working around limitations when using
it. (In particular having a unique constraint accross all derived tables is a
pain.)

I wouldn't repeat the columns in the actual tables you are using. Instead
the derived tables should refer to the base table using a foriegn key.
You can then use views (and rules if you need the views to be updateable.)
to make derived tables in queries with the columns from the base tables.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #2

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

Similar topics

1
2268
by: Justin | last post by:
Hi, In the process of localizing the 'regions' table, we added three new tables. The localized data will be stored in the TokenKeys and TokenValues tables. It would be easier if we did away with the TokeyKeys/TokenValues tables and just added a localeid in the regions table, but this is the desired schema by the client. Here's the schema: Table: regions
25
11093
by: Andreas Fromm | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Im building an user database with many tables keeping the data for the Address, Phone numbers, etc which are referenced by a table where I keep the single users. My question is, how do I get the "Id"-value of a newly inserted address to store it in the referencing user table:
6
1975
by: Ted Stewart | last post by:
I've got a table with an autogenerated number as it's primary key, which is being accessed by an external .NET app. When the app inserts a new record into the table, is there any way to return the ID? Using a "SELECT FROM table WHERE (repeat of inserted data) ORDER BY " and selecting the largest ID would probably work, but that's extremely clunky. I'm new to databases in general, but this should be a common enough problem that...
4
2607
by: Daisy | last post by:
Let's say I've got a forum, where users can be moderators of each forum. Tables look like this: USER -------- user_key name FORUM
0
888
by: Sparky Arbuckle | last post by:
The function below works in that it returns the correct data back to the dataset for 2 of the rows in my datalist: A1 - A - 1 A1 - A - 2 A1 - A - 3 A1 - B - 1 A1 - B - 2 A1 - C - 1 A1 - C - 2
10
6406
by: MaRCeLO PeReiRA | last post by:
Hi guys, I am in troubles with a SERIAL field. I have five tables. A parent table and four child tables. When I do the INSERT in the parent table, I have an ID (generated) by the sequence (SERIAL field), and I have to use this ID to reference all child tables.
6
5213
by: Rico | last post by:
Hello, I'm creating an audit table and associated triggers to be able to capture any updates and deletes from various tables in the database. I know how to capture the records that have been updated or deleted, but is there any way that I can cycle through a changed record, look at the old vs new values and capture only the values that have changed? To give you a better idea of what I'm trying to do, instead of creating a copy of the...
6
8152
by: Bhawna | last post by:
I am into c++ code maintenance for last 3-4 years but recently I am put into design phase of a new project. Being a small comapany I dont have enough guidance from seniors. Currently I am into a situation where I am implementing base class functions by including a pointer to subclass member in base class. Reason being functionality is common for subclasses but the members are common within subclass only (static member of subclass) but...
0
8411
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
8838
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
8739
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...
0
8613
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
7351
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
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2740
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
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.