Re: [HACKERS] Inherited constraints and search paths (was Re: [GENERAL] Preserving data after updates)

2005-05-20 Thread Tom Lane
Berend Tober <[EMAIL PROTECTED]> writes: >> On Thu, 2005-05-19 at 23:27 -0400, Tom Lane wrote: >>> OK, now I finally get the point: you are creating child tables in >>> different schemas than their parents live in. >> > The case in question was not one of the child table being in a different >

Inherited constraints and search paths (was Re: [GENERAL] Preserving data after updates)

2005-05-19 Thread Tom Lane
Berend Tober <[EMAIL PROTECTED]> writes: > Now what, oh most wise one? OK, now I finally get the point: you are creating child tables in different schemas than their parents live in. This creates a problem because reverse-listing of the constraints varies depending on what the search path is. An

Re: [GENERAL] Preserving data after updates

2005-05-19 Thread Berend Tober
Tom Lane wrote: What do you get from select conname, consrc from pg_catalog.pg_constraint where contype = 'c' and conrelid = 'person'::regclass; conname | consrc -

Re: [GENERAL] Preserving data after updates

2005-05-19 Thread Tom Lane
Berend Tober <[EMAIL PROTECTED]> writes: > Interesting. The consrc column values differ in that the explicit schema > qualification on the function calls is missing for the descendent table. > So, you think maybe if I remove the explicit schema qualification from > the function calls in the cons

Re: [GENERAL] Preserving data after updates

2005-05-19 Thread Berend Tober
Tom Lane wrote: What do you get from select conname, consrc from pg_catalog.pg_constraint where contype = 'c' and conrelid = 'person'::regclass; conname | consrc --

Re: [GENERAL] Preserving data after updates

2005-05-19 Thread Tom Lane
Berend Tober <[EMAIL PROTECTED]> writes: > I tried a simpler example than my original, as you have, and the problem > bahavior didn't manifest, but it still happens in my dev copy of my > production database. The immediately obvious difference between the > simpler example, like yours, and the a

Re: [GENERAL] Preserving data after updates

2005-05-19 Thread Berend Tober
Tom Lane wrote: The case I tested seems to work in 7.3 as well: CREATE TABLE person (last_name varchar(24), first_name varchar(24), CONSTRAINT person_name_check CHECK (((last_name IS NOT NULL) OR (first_name IS NOT NULL; CREATE TABLE person_change_history( action VARCHAR(6), update_dat

Re: [GENERAL] preserving data after updates

2005-05-19 Thread Berend Tober
Greg Patnude wrote: Yeah… this is where the inheritance model gets a little funky… What do you have “SQL_INEHERITANCE” set to when you dump the database ? I’ve never tested this so I don’t know if it makes a difference being on or off when you dump a table…. You might try it and compare the two

Re: [GENERAL] Preserving data after updates

2005-05-19 Thread Tom Lane
Berend Tober <[EMAIL PROTECTED]> writes: > Tom Lane wrote: >> Hmm, it shouldn't do that ... and in a quick test here I couldn't >> reproduce any such bug. What version of pg_dump are you using? > Sorry I failed to specify. Production version is 7.3.1 (change is > hard!), although I origianally w

Re: [GENERAL] Preserving data after updates

2005-05-19 Thread Berend Tober
Tom Lane wrote: Berend Tober <[EMAIL PROTECTED]> writes: But after doing a dump of the modified data base, the script created by pg dump wants to recreate the history table as ... CONSTRAINT person_name_check CHECK (((last_name IS NOT NULL) OR (first_name IS NOT NULL))), Hmm, it shouldn

Re: [GENERAL] Preserving data after updates

2005-05-19 Thread Tom Lane
Berend Tober <[EMAIL PROTECTED]> writes: > But after doing a dump of the modified data base, the script created by > pg dump wants to recreate the history table as > ... > CONSTRAINT person_name_check CHECK (((last_name IS NOT NULL) OR > (first_name IS NOT NULL))), Hmm, it shouldn't do that .

[GENERAL] Preserving data after updates

2005-05-19 Thread Berend Tober
A few months ago, a question by Scott Frankel produced a suggestion from Greg Patnude which I found very exciting that had to do with using pg table inheritance to maintain an audit or row change history table. I've been testing Patnude's idea and ran into a problem, described below, and wanted

Re: [GENERAL] preserving data after updates

2005-03-05 Thread Karsten Hilbert
> Its called a "temporal database". > Usually its intended for medical or police databases where > you need a hind sight. i.e. if today is 31/12/2005, what did we know at > 20/12/2005. > for example, for a doctor appearing at court and required to testify > what he knew at 20/12/2005. What he "can

Re: [GENERAL] preserving data after updates

2005-03-05 Thread Martijn van Oosterhout
On Sat, Mar 05, 2005 at 03:46:53AM +0200, Tzahi Fadida wrote: > Its called a "temporal database". > Usually its intended for medical or police databases where > you need a hind sight. i.e. if today is 31/12/2005, what did we know at > 20/12/2005. > for example, for a doctor appearing at court and

Re: [GENERAL] preserving data after updates

2005-03-04 Thread Tzahi Fadida
ql-general@postgresql.org > Subject: [GENERAL] preserving data after updates > > > > Is there a canonical form that db schema designers use > to save changes to the data in their databases? > > For example, given a table with rows of data, if I UPDATE > a field in a row,

Re: [GENERAL] preserving data after updates

2005-03-04 Thread Greg Patnude
-Original Message- From: Berend Tober [mailto:[EMAIL PROTECTED] Sent: Friday, March 04, 2005 8:47 AM To: Greg Patnude Cc: pgsql-general@postgresql.org Subject: Re: [GENERAL] preserving data after updates > I use a modified form of option 3 with an ON UPDATE RULE the update r

Re: [GENERAL] preserving data after updates

2005-03-04 Thread Scott Frankel
Door number 3. Thanks for the responses and terrific suggestions! Scott On Mar 4, 2005, at 8:28 AM, Greg Patnude wrote: I use a modified form of option 3 with an ON UPDATE RULE the update rule copies the row to an inherited table... CREATE TABLE dm_user ( id SERIAL NOT NULL PRIMARY KE

Re: [GENERAL] preserving data after updates

2005-03-04 Thread Berend Tober
> I use a modified form of option 3 with an ON UPDATE RULE the update rule > copies the row to an inherited table... I just gotta say that THAT is one COOL use of PG inheritance! Do you find that it works well and is robust and all the good stuff it seems like would be the case? -- Berend

Re: [GENERAL] preserving data after updates

2005-03-04 Thread Greg Patnude
I use a modified form of option 3 with an ON UPDATE RULE the update rule copies the row to an inherited table... CREATE TABLE dm_user ( id SERIAL NOT NULL PRIMARY KEY, lu_user_type INTEGER NOT NULL REFERENCES lu_user_type(id), dm_user_address INTEGER NOT NULL DEFAULT 0,

Re: [GENERAL] preserving data after updates

2005-03-04 Thread Ian Harding
I do option 3. A generic trigger writes the tablename, field name, type of change (insert/update/delete) and the old and new values for columns that were affected. It is kind of a hog, but it works very well. I have cron delete old entries so it doesn't eat my whole disk. I haven't tried to ge

[GENERAL] preserving data after updates

2005-03-03 Thread Scott Frankel
Is there a canonical form that db schema designers use to save changes to the data in their databases? For example, given a table with rows of data, if I UPDATE a field in a row, the previous value is lost. If I wanted to track the changes to my data over time, it occurs to me that I could, 1) cop