Hi all. I have a table with the following structure (NOTE: I'm only describing the columns affected by the indeces in question):
x_id is the primary key, so by default has a unique index created.
I've also created a unique index on the a_id, p_id, c_id, g_id, and u_id columns.
However, I was recently able to insert two identical columns into this table (x_id = 2 and x_id = 4):
Now, the default value for c_id is null, so I'm going to make what I think is a safe assumption in that unique indexes cannot include a column which contains a null value.
However, to get all the functionality I need, I REALLY need to have c_id be allowed to be null.
Can anyone advise me if this is indeed what's causing the problem, and if so if there is any way around it?
Thanks very much in advance,
Pablo
Code:
cms=# \d cms_access;
Table "cms_access"
Column | Type | Modifiers
---------------+--------------------------------+---------------------------------------
x_id | integer | not null default nextval('"cms_access_seq"'::text)
a_id | integer | not null
p_id | integer | not null
c_id | integer | default null
g_id | integer | not null
u_id | integer | not null
x_id is the primary key, so by default has a unique index created.
I've also created a unique index on the a_id, p_id, c_id, g_id, and u_id columns.
However, I was recently able to insert two identical columns into this table (x_id = 2 and x_id = 4):
Code:
cms=# select * from cms_access;
x_id | a_id | p_id | c_id | g_id | u_id |
------+------+------+------+------+------+
1 | 1 | 1 | | 1 | 1 |
2 | 1 | 2 | | 1 | 1 |
4 | 1 | 2 | | 1 | 1 |
Now, the default value for c_id is null, so I'm going to make what I think is a safe assumption in that unique indexes cannot include a column which contains a null value.
However, to get all the functionality I need, I REALLY need to have c_id be allowed to be null.
Can anyone advise me if this is indeed what's causing the problem, and if so if there is any way around it?
Thanks very much in advance,
Pablo