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
www.ZotConsulting.com
www.WhiteKnightHackers.com