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

From David Blomstrom
Subject Re: Hierarchical Query Question (PHP)
Date
Msg-id CAA54Z0gjz+bTeu1W0Dc+OwTNvhmCicsn0pvwwfzqMmfy5x8HmQ@mail.gmail.com
Whole thread Raw
In response to Re: Hierarchical Query Question (PHP)  ("Jason O'Donnell" <odonnelljp01@gmail.com>)
Responses Re: Hierarchical Query Question (PHP)  (Andy Colson <andy@squeakycode.net>)
List pgsql-general
No, I get the same T_FUNCTION error.

Someone commented that the function...

  create function tax_rank(id integer) returns text as $$
    select case id
             when 1 then 'Classes'
             when 2 then 'Orders'
             when 3 then 'Families'
             when 4 then 'Genera'
             when 5 then 'Species'
           end;
  $$ language sql;

...should ideally be part of the table schema. Does that mean I need to go into pgAdmin, open up my table and paste this in somehow?

I wonder if the function is even necessary. My goal is to create a hierarchical query that displays the number of children, grandchildren, etc. And, depending on the taxonomic level, it might display the result as "20 families, 74 genera and 413 species." With MySQL I could probably turn that into a series of echo values, which I could then display like this:

echo ''.$NumberChildren.' families<br>
'.$NumberGrandchildren.' genera<br>
'.$NumberGreatgrandchildren.' species';

I'm wondering if I should figure out this query or go back to square one with a simpler query. I've never seen a query with a function before. ;)

Thanks for the tips.

pgsql-general by date:

Previous
From: Jim Nasby
Date:
Subject: Re: pgxs/config/missing is... missing
Next
From: Andy Colson
Date:
Subject: Re: Hierarchical Query Question (PHP)