Re: [GENERAL] Foreign keys/unique values and views

2001-03-22 Thread Einar Karttunen

On Thu, 22 Mar 2001, Richard Huxton wrote:

 I have to admit I've never tried referencing a view with a foreign key. I
 don't know if it's possible and I have to admit the idea makes me
 uncomfortable. Can't give a good reason why, but I'd apply constraints at
 the table level.
if one can reference a table with a foreign key it makes possible to
reference inheritance hierarchies. If I create a view from the parent
with CREATE VIEW name SELECT * FROM parent; (in v.7.1) it should contain
the entries from the children as well. Now if I could reference this view
I could simulate referencing parent and child tables easily.
What I have in mind is a hierarchy of persons all inheriting from a table
called person. Different kinds of persons have different attributes but
all have an id and name. What I want is that other tables could reference
these persons easily.

- Einar Karttunen



---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html



Re: [GENERAL] Foreign keys/unique values and views

2001-03-22 Thread Martijn van Oosterhout

On Thu, Mar 22, 2001 at 06:33:16PM -0500, Jan Wieck wrote:
 Einar Karttunen wrote:
 How do you put a UNIQUE constraint on the entire  inheritance
 hierarchie?

Easy. You make a unique index that covers an entire inheritance hierarchy.
If lots of table inherit a field "id" from a single table the you can put a
unique index on that field. All you need then is an index whose keys
reference not tuple IDs but (table ID, tuple ID) pairs.

Wow. I'm just thinking of how vacuum would deal with this. Probably not very
well. But it would give inheritance hierarchies very efficient lookups
rather than the implicit unioning done currently.

Martijn

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster