Re: Hierarchical Query Question (PHP)

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: David Blomstrom <david(dot)blomstrom(at)gmail(dot)com>, Andy Colson <andy(at)squeakycode(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Hierarchical Query Question (PHP)
Date: 2015-10-30 22:21:36
Message-ID: 5633ED70.6090701@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 30/10/2015 22:10, David Blomstrom wrote:
> Just so I understand what's going on, I can create a lookup table by
> pasting this code...
>
> create table taxon (
> taxonid serial,
> descr text
> );
> create table gz_life_mammals (
> id serial,
> taxonid integer, -- use the lookup table
> parentid integer -- use the lookup table
> );
>
> ...into pgAdmin III, right? (I can't use the shell/terminal at the
> moment, and it will be at least a few weeks before I can get it fixed.)
> And this script will create TWO tables - gz_life_mammals and a matching
> "lookup table"?

Yes, it will. I haven't seen, what went before in this thread so may
have missed stuff, but you should also add a foreign key constraint
between the tables (for taxonid anyway, dunno what parentid refers to):

create table gz_life_mammals (
id serial,
taxonid integer, -- use the lookup table
parentid integer, -- use the lookup table

constraint mammals_taxon_fk foreign key (taxonid) references
taxon(taxonid)

);

If parentid also references taxon.taxonid, add a similar constraint for
it too,

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Blomstrom 2015-10-30 22:29:08 Re: Hierarchical Query Question (PHP)
Previous Message Rob Sargent 2015-10-30 22:18:39 Re: Hierarchical Query Question (PHP)