Re: [GENERAL] partial "on-delete set null" constraint

2015-02-15 Thread Rafal Pietrak
W dniu 03.02.2015 o 04:44, Jim Nasby pisze: On 1/3/15 2:49 AM, Rafal Pietrak wrote: [---] But an application could do -a successfull scenario with expected result--- testvm=# UPDATE mailboxes SET username = null; UPDATE 1 testvm=# DELETE FROM mail

Re: [GENERAL] partial "on-delete set null" constraint

2015-02-02 Thread Jim Nasby
On 1/3/15 2:49 AM, Rafal Pietrak wrote: -test schema--- CREATE TABLE maildomains (domain text primary key, profile text not null); CREATE TABLE mailusers (username text , domain text references maildomains(domain) on update cascade, primary key (username, domain)); C

Re: Fwd: [GENERAL] partial "on-delete set null" constraint

2015-01-26 Thread Kevin Grittner
Alban Hertroys wrote: > Unfortunately, I do not own a copy so I can't verify. If anyone > who does own a copy could confirm or even quote the relevant > section, that would be great. I have a copy of The RELATIONAL MODEL for DATABASE MANAGEMENT, VERSION 2 (RM/V2), by E. F. Codd, Copyright 1990,

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-25 Thread Paul Jungwirth
> 1. I have a table with mailmessages, which has an FK to a table of hub users. > 2. I'd like to retain the content of message repository (with it's domain key > not cleared), when I drop a particular username from service to release > that username to others. > 3. I try to do that with FK "

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-25 Thread Alban Hertroys
> On Sun, 2015-01-25 at 14:09 +0100, Alban Hertroys wrote: > > The following link > > http://www.databaseanswers.org/codds_rules.htm > > sets out Ted Codd's rules according to C.J. Date. As you might have noticed, those were referred to already upthread, but that is a while ago now. Although

Re: Fwd: [GENERAL] partial "on-delete set null" constraint

2015-01-25 Thread rob stone
On Sun, 2015-01-25 at 14:09 +0100, Alban Hertroys wrote: > >> The theory got me intrigued. google > >> (http://en.wikipedia.org/wiki/Codd%27s_12_rules) says: > >> rule 3: "systematic treatment of null values"; hmmm this is a little > >> broader then "support for null". I would think, that:

Fwd: [GENERAL] partial "on-delete set null" constraint

2015-01-25 Thread Alban Hertroys
>> The theory got me intrigued. google >> (http://en.wikipedia.org/wiki/Codd%27s_12_rules) says: >> rule 3: "systematic treatment of null values"; hmmm this is a little >> broader then "support for null". I would think, that: >> 1. if a sequence of "update XX set fk_field=null; then delete Y

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-04 Thread Rafal Pietrak
W dniu 04.01.2015 o 02:02, Alban Hertroys pisze: [--] "A table can have at most one primary key, but it may have more than one candidate key. A primary key is a combination of columns which uniquely specify a row; it is a special case of unique keys. One difference

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Alban Hertroys
> On 03 Jan 2015, at 23:14, Rafal Pietrak wrote: >> Well, that’s embarrassing, it’s only a few weeks since I learned this and >> I’m already attributing the theory to the wrong database deity! That’s >> Codd-relationality, of course. Not Boyce. > > The theory got me intrigued. google > (http:

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Rafal Pietrak
A supporting view works OK. - CREATE VIEW api2users AS SELECT * from mailusers; CREATE or replace RULE remove_user AS ON DELETE TO api2users do instead (update mailboxes set username=null where username=old.username and domain=old.domain; delete from mailusers where usern

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Alban Hertroys
> On 03 Jan 2015, at 18:05, Rafal Pietrak wrote: > W dniu 03.01.2015 o 16:48, Alban Hertroys pisze: >>> On 03 Jan 2015, at 15:20, Rafal Pietrak wrote: >>> > [-] >>> Yes. This is precisely the "semantics" I'm trying to put into the schema: >>> after a username is "releas

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Alban Hertroys
> On 03 Jan 2015, at 14:11, Alban Hertroys wrote: > > On 02 Jan 2015, at 13:31, Rafal Pietrak wrote: >> Would it violate SQL standard (signifficantly), if an "on delete set null" >> action just ignored all the FK columns that have a "NOT NULL" constraint set? > > As I understand it, this is p

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Adrian Klaver
On 01/03/2015 09:05 AM, Rafal Pietrak wrote: W dniu 03.01.2015 o 16:48, Alban Hertroys pisze: On 03 Jan 2015, at 15:20, Rafal Pietrak wrote: [-] Yes. This is precisely the "semantics" I'm trying to put into the schema: after a username is "released" from service, all

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Rafal Pietrak
W dniu 03.01.2015 o 16:48, Alban Hertroys pisze: On 03 Jan 2015, at 15:20, Rafal Pietrak wrote: [-] Yes. This is precisely the "semantics" I'm trying to put into the schema: after a username is "released" from service, all it's messages become "from unknown user"

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Alban Hertroys
> On 03 Jan 2015, at 15:20, Rafal Pietrak wrote: > > W dniu 03.01.2015 o 14:11, Alban Hertroys pisze: > [--] >> You assumed a functional dependency between username and domain, while those >> fields actually describe independent entities that don’t necessarily go >> together as

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Rafal Pietrak
W dniu 03.01.2015 o 16:07, Adrian Klaver pisze: On 01/03/2015 12:49 AM, Rafal Pietrak wrote: [-] With TRIGGER alone (i.e. without "documenting FK"), one will have to analize the body of an "ever growing" function. Which at certain point would become too much of an effort

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Adrian Klaver
On 01/03/2015 12:49 AM, Rafal Pietrak wrote: W dniu 02.01.2015 o 20:37, Adrian Klaver pisze: On 01/02/2015 08:55 AM, Rafal Pietrak wrote: [--] Is there a way to forcebly push the "old.username=null, throughout the "on-update" FK chains into the all dependent tables, before co

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Rafal Pietrak
W dniu 03.01.2015 o 14:11, Alban Hertroys pisze: [--] You assumed a functional dependency between username and domain, while those fields actually describe independent entities that don’t necessarily go together as you found out. Hence you need to normalise further. For exampl

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Alban Hertroys
On 02 Jan 2015, at 13:31, Rafal Pietrak wrote: > > Hello, > > Rewriting my mail-hub I fell into the following problem: > 1. I have a table with mailmessages, which has an FK to a table of hub users. > 2. I'd like to retain the content of message repository (with it's domain key > not cleared),

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-03 Thread Rafal Pietrak
W dniu 02.01.2015 o 20:37, Adrian Klaver pisze: On 01/02/2015 08:55 AM, Rafal Pietrak wrote: [--] Is there a way to forcebly push the "old.username=null, throughout the "on-update" FK chains into the all dependent tables, before constraints are checked for DELETE operation? I

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-02 Thread Adrian Klaver
On 01/02/2015 08:55 AM, Rafal Pietrak wrote: W dniu 02.01.2015 o 17:05, Adrian Klaver pisze: On 01/02/2015 07:45 AM, Rafal Pietrak wrote: W dniu 02.01.2015 o 16:03, Adrian Klaver pisze: On 01/02/2015 04:31 AM, Rafal Pietrak wrote: [] CCing the list. Ups, sorry - no

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-02 Thread Rafal Pietrak
W dniu 02.01.2015 o 17:05, Adrian Klaver pisze: On 01/02/2015 07:45 AM, Rafal Pietrak wrote: W dniu 02.01.2015 o 16:03, Adrian Klaver pisze: On 01/02/2015 04:31 AM, Rafal Pietrak wrote: [] CCing the list. Ups, sorry - not that button clicked. [-

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-02 Thread Adrian Klaver
On 01/02/2015 07:45 AM, Rafal Pietrak wrote: W dniu 02.01.2015 o 16:03, Adrian Klaver pisze: On 01/02/2015 04:31 AM, Rafal Pietrak wrote: [] CCing the list. Not sure about the standard, but pretty sure it will foul things up in general. From the table structures abov

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-02 Thread Adrian Klaver
On 01/02/2015 04:31 AM, Rafal Pietrak wrote: Hello, Rewriting my mail-hub I fell into the following problem: 1. I have a table with mailmessages, which has an FK to a table of hub users. 2. I'd like to retain the content of message repository (with it's domain key not cleared), when I drop a par

Re: [GENERAL] partial "on-delete set null" constraint

2015-01-02 Thread Melvin Davidson
Your main problem is that column "domain" of mailboxes is specified as NOT NULL, so of course the "SET NULL" option will not work. Here is the full message I see when I execute your code, which should be self explanatory. ERROR: null value in column "domain" violates not-null constraint DETAIL:

[GENERAL] partial "on-delete set null" constraint

2015-01-02 Thread Rafal Pietrak
Hello, Rewriting my mail-hub I fell into the following problem: 1. I have a table with mailmessages, which has an FK to a table of hub users. 2. I'd like to retain the content of message repository (with it's domain key not cleared), when I drop a particular username from service to relea