Re: Hierarchical Query Question (PHP) - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: Hierarchical Query Question (PHP)
Date
Msg-id 5633ED70.6090701@iol.ie
Whole thread Raw
In response to Re: Hierarchical Query Question (PHP)  (David Blomstrom <david.blomstrom@gmail.com>)
Responses Re: Hierarchical Query Question (PHP)
List 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@iol.ie


pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: Hierarchical Query Question (PHP)
Next
From: David Blomstrom
Date:
Subject: Re: Hierarchical Query Question (PHP)