pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedTracking depth question
2+ messages / 2 participants
[nested] [flat]
* Tracking depth question
@ 1999-11-04 17:39 Zot O'Connor <zot@zotconsulting.com>
1999-11-05 06:48 ` Re: [SQL] Tracking depth question Zalman Stern <zalman@netcom.com>
0 siblings, 1 reply; 2+ messages in thread
From: Zot O'Connor @ 1999-11-04 17:39 UTC (permalink / raw)
To: postgres sql <pgsql-sql@hub.org>
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [SQL] Tracking depth question
1999-11-04 17:39 Tracking depth question Zot O'Connor <zot@zotconsulting.com>
@ 1999-11-05 06:48 ` Zalman Stern <zalman@netcom.com>
0 siblings, 0 replies; 2+ messages in thread
From: Zalman Stern @ 1999-11-05 06:48 UTC (permalink / raw)
To: zot@zotconsulting.com; +Cc: pgsql-sql@hub.org
> scatdepth integer DEFAULT (SELECT scatval from scattab where scatval =
> scatscat) + 1,
I think you mean "(SELECT scatdepth from scattab where scatval = scatscat)
+ 1" . (Perhaps you might consider calling scatscat "scatparent" instead.)
How about defining a function and setting the default to its return value?
-Z-
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1999-11-05 06:48 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-11-04 17:39 Tracking depth question Zot O'Connor <zot@zotconsulting.com>
1999-11-05 06:48 ` Zalman Stern <zalman@netcom.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox