Re: A few questions about ltree

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: A few questions about ltree
Date: 2006-04-21 14:28:01
Message-ID: 4448EBF1.4040708@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Teodor Sigaev wrote:
>> Maybe something along the lines of the following is possible?:
>
> Exact, it's for what ltree was developed.

Cool, looks like it is what I need then.

> contrib_regression=# select 'a.b.c' <@ 'a.b'::ltree;
> ?column?
> ----------
> t
> (1 row)

How would you use this to constrain a foreign key?

We've been experimenting with a table containing a branch 'a', 'a.b' and
'a.b.c', but deleting 'a.b' didn't cause a constraint violation.

SQL> CREATE TABLE ltree_test (path ltree PRIMARY KEY REFERENCES
ltree_test(path));
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"ltree_test_pkey" for table "ltree_test"
CREATE TABLE
SQL> INSERT INTO ltree_test VALUES ('a'::ltree);
INSERT 84117368 1
SQL> INSERT INTO ltree_test VALUES ('a.b'::ltree);
INSERT 84117369 1
SQL> INSERT INTO ltree_test VALUES ('a.b.c'::ltree);
INSERT 84117370 1
SQL> DELETE FROM ltree_test WHERE path = 'a.b'::ltree;
DELETE 1
SQL> select * from ltree_test;
path
-------
a
a.b.c
(2 rows)

Is there some obvious/easy way to prevent this?

Regards,
--
Alban Hertroys
alban(at)magproductions(dot)nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

// Integrate Your World //

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2006-04-21 14:28:40 Re: How to replace rows in table so that foreign key rows
Previous Message Tomi NA 2006-04-21 14:20:00 Re: setting the environment locale - linux, windows