From: | "Zot O'Connor" <zot(at)zotconsulting(dot)com> |
---|---|
To: | postgres sql <pgsql-sql(at)hub(dot)org> |
Subject: | Tracking depth question |
Date: | 1999-11-04 17:39:59 |
Message-ID: | 3821C4EF.CE5484E@zotconsulting.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I have a shopping cart (FishCartSQL) and I have a client with many
layers of sub categories (at least 4, maybe more).
The current system only has 1 subcategory, I am extending it.
I am planning on having subcats reference themselves with a scatscat
value which will need to point to scatval (a subcat ID).
I know that foreign key does not work, and I will accept that for now,
but my issue is tracking the depth of the subcat within the DB.
I would rather not rely on external SQL (php) to do the job. The
problem is that I am not sure I can reference the depth in the table
definition. I would like something like this:
CREATE TABLE scattab
scatval integer DEFAULT NEXTVAL('scatid_SEQ') PRIMARY KEY,
scatscat integer FOREIGN KEY(scattab.scatval),
scatdepth integer DEFAULT (SELECT scatval from scattab where scatval =
scatscat) + 1,
...
Now there are a few problems that I see
1) scatscat is not defined yet
2) I don't think I can default to a select
3) I am assuming an atomic value for the SELECT statement
Is there a better Clean way?
I was thinking a trigger that fires a separate depth table and adds the
values of scatval and its depth.
Any ideas?
--
Zot O'Connor
From | Date | Subject | |
---|---|---|---|
Next Message | Drinks, Ivan - ITD | 1999-11-04 22:19:04 | Remove |
Previous Message | Stoyan Genov | 1999-11-04 12:59:03 | Re: [SQL] Optimizing a query through its syntax and indices |