pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Zot O'Connor <zot@zotconsulting.com>
To: postgres sql <pgsql-sql@hub.org>
Subject: Tracking depth question
Date: Thu, 04 Nov 1999 09:39:59 -0800
Message-ID: <3821C4EF.CE5484E@zotconsulting.com> (raw)

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



view thread (2+ messages)  latest in thread

Message-ID: <3821C4EF.CE5484E@zotconsulting.com>
Permalink:  ../3821C4EF.CE5484E@zotconsulting.com/
Also on:    postgresql.org/message-id/3821C4EF.CE5484E@zotconsulting.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: zot@zotconsulting.com, pgsql-sql@hub.org
  Subject: Re: Tracking depth question
  In-Reply-To: <3821C4EF.CE5484E@zotconsulting.com>
  References: <3821C4EF.CE5484E@zotconsulting.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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