>>A row in the table is a tree node. A node can have one parent, ot no
>>parent at all.
>
>
> You're better off making the root node link to itself (compare handling
> of /.. in a Unix filesystem). NULL parent link does not mean "has no
> parent", it means "parent is unknown".
>
Great idea! I'll do that. Thanks!
What about another example:
create table user
(
id serial primary key,
login text not null unique
);
create table tag_set
(
id serial primay key,
tag text not null unique,
data text not null,
userid int references users on delete cascade on update cascade
);
The idea is that 'tags' may be user-specific or user-independent - so
that to get a set of tags for a given user, I would do
select tag,data from tag_set where userid is null or userid=?
with my 'workaround' solution I do
select tag,data from tag_set where userid==null or userid=?
(where '==' is my special non-strict operator)
to force both parts of the criteria to use the index
Any ideas how to do this better (again, other than creating a dummy user
with id 0)?
I'll apppreciate any suggestions...
Thanks a lot!
Dima