niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » IBM DB2
UNIQUE WHERE NOT NULL
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
Author Message
Knut Stolze
*nix forums Guru


Joined: 28 Jul 2005
Posts: 755

PostPosted: Mon Feb 07, 2005 6:45 am    Post subject: Re: UNIQUE WHERE NOT NULL Reply with quote

ak_tiredofspam@yahoo.com wrote:

Quote:
Knut,

just imagine:

insert into t(primarykey, notnullu­nique)values(1,null);

in Bob's index there is (1);
in mine there is (1,null);

You are correct. I missed the part where the index is created on two
columns. Now it makes sense to me.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Back to top
ak_tiredofspam@yahoo.com
*nix forums beginner


Joined: 02 May 2005
Posts: 28

PostPosted: Thu Feb 03, 2005 2:12 pm    Post subject: Re: UNIQUE WHERE NOT NULL Reply with quote

Knut,

just imagine:

insert into t(primarykey, notnullu­nique)values(1,null);

in Bob's index there is (1);
in mine there is (1,null);

insert into t(primarykey, notnullu­nique)values(2,1);
---- should be OK, correct?

that would add another (1) to Bob's index - FAIL, IT'S A UNIQUE INDEX
in mine there are (1,null) and (null,1) - still OK

When I was typing
case when notnullunique is null then primarykey end
I meant

case when notnullunique is null then primarykey ELSE NULL end

which is not equivalent to COALESCE, which is

case when notnullunique is null then primarykey ELSE NOTNULLUNIQUE end

What do you think?
Alexander
Back to top
Knut Stolze
*nix forums Guru


Joined: 28 Jul 2005
Posts: 755

PostPosted: Thu Feb 03, 2005 6:18 am    Post subject: Re: UNIQUE WHERE NOT NULL Reply with quote

ak_tiredofspam@yahoo.com wrote:

Quote:
it's a brilliant idea, it only needs a little modification:

alter table t
add column pseudokey generated always as
(case when notnullunique is null then primarykey end);
create unique index u_ind on the_table(pseudokey, notnullunique);

Why do you need the modifications? The COALESCE is exactly the same
(semantically) as the CASE expression you used. And the UNIQUE constraint
creates a unique index under the covers too.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Back to top
Mark Yudkin
*nix forums Guru Wannabe


Joined: 29 May 2005
Posts: 117

PostPosted: Thu Feb 03, 2005 6:15 am    Post subject: Re: UNIQUE WHERE NOT NULL Reply with quote

I suggest you open a "requirement" through your local IBM support. That way,
you at least get noticed. And the more they receive such requirements, the
better the chances that IBM will start to address these sorts of unnecessary
and frustrating incompatibilities.

And yes, it's a very big nuisance. Some things take years to move from
mainframe DB2 to UDB (e.g. versioned packages), others, like results sets in
embedded CALLs, UNIQUE WHERE NOT NULL, or an intelligent REBIND command,
still haven't been done.

"Mark A" <nobody@nowhere.com> wrote in message
news:XuydnYhxTfYrrpzfRVn-og@comcast.com...
Quote:
UNIQUE WHERE NOT NULL is supported in DB2 for z/OS, which allows for
duplicate null values to exist on a unique constraint.

Anyone know if or when this is coming to DB2 for LUW?

Back to top
ak_tiredofspam@yahoo.com
*nix forums beginner


Joined: 02 May 2005
Posts: 28

PostPosted: Wed Feb 02, 2005 10:12 pm    Post subject: Re: UNIQUE WHERE NOT NULL Reply with quote

it's a brilliant idea, it only needs a little modification:

alter table t
add column pseudokey generated always as
(case when notnullunique is null then primarykey end);
create unique index u_ind on the_table(pseudokey, notnullunique);
Back to top
Vincent M
*nix forums Guru


Joined: 22 Feb 2005
Posts: 1332

PostPosted: Wed Feb 02, 2005 9:26 pm    Post subject: Re: UNIQUE WHERE NOT NULL Reply with quote

"Bob Stearns" <rstearns1241@charter.net> wrote in message
news:JlbMd.4715$%u7.1162@fe03.lga...
Quote:
Not being IBM I can't answer the original question, but I can suggest a
reasonably easy to do the same thing. Suppose a table t, with at least
primarykey, and notnullunique columns. The following (barring any typing
or memory lapses on my part) should do what what you want.

alter table t
add column pseudokey generated always as
colaesce(notnullunique, primarykey);

alter table t
add constraint uniqpseudo unique (pseudokey);

These can be combined into one statement, but the intent is clearer as
two.


2 Big assumptions need to be made for this to work:

1) There are no data type or length issues between the two columns
2) There is no way that the primary key could be a valid value on the other
column that you are testing for uniqueness.
Back to top
Bob Stearns
*nix forums Guru Wannabe


Joined: 01 Jun 2005
Posts: 224

PostPosted: Wed Feb 02, 2005 8:07 pm    Post subject: Re: UNIQUE WHERE NOT NULL Reply with quote

Mark A wrote:
Quote:
UNIQUE WHERE NOT NULL is supported in DB2 for z/OS, which allows for
duplicate null values to exist on a unique constraint.

Anyone know if or when this is coming to DB2 for LUW?


Not being IBM I can't answer the original question, but I can suggest a

reasonably easy to do the same thing. Suppose a table t, with at least
primarykey, and notnullunique columns. The following (barring any typing
or memory lapses on my part) should do what what you want.

alter table t
add column pseudokey generated always as
colaesce(notnullunique, primarykey);

alter table t
add constraint uniqpseudo unique (pseudokey);

These can be combined into one statement, but the intent is clearer as two.
Back to top
Vincent M
*nix forums Guru


Joined: 22 Feb 2005
Posts: 1332

PostPosted: Wed Feb 02, 2005 7:12 pm    Post subject: UNIQUE WHERE NOT NULL Reply with quote

UNIQUE WHERE NOT NULL is supported in DB2 for z/OS, which allows for
duplicate null values to exist on a unique constraint.

Anyone know if or when this is coming to DB2 for LUW?
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 2:52 am | All times are GMT
navigation Forum index » Databases » IBM DB2
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts "CHARACTER SET COLLATE NULL" error with mySQL 4.0.27 thomas Armstrong MySQL 1 Thu Jul 20, 2006 9:11 am
No new posts Constraint for two fields unique any order MargaretGillon@chromalloy PostgreSQL 5 Wed Jul 19, 2006 4:01 pm
No new posts 2.6S1 - assertion failed: authenticate.c:836: "auth_user_... Covington, Chris Squid 1 Tue Jul 18, 2006 2:16 pm
No new posts unique generated numbers mob1012 IBM DB2 2 Tue Jul 18, 2006 1:58 pm
No new posts Null reference David White C++ 27 Tue Jul 18, 2006 5:17 am

Mortgages | Credit Cards | Debt Consolidation | MPAA | Sprint Ringtones
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1234s ][ Queries: 20 (0.0387s) ][ GZIP on - Debug on ]