Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-31 Thread David Blomstrom
Awesome; thanks! On Sat, Oct 31, 2015 at 7:19 AM, Andy Colson wrote: > On 10/30/2015 05:10 PM, David Blomstrom wrote: > >> Just so I understand what's going on, I can create a lookup table by >> pasting this code... >> >> > I don't know anything about biology so this data might be laughable, but

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-31 Thread Andy Colson
On 10/30/2015 05:10 PM, David Blomstrom wrote: Just so I understand what's going on, I can create a lookup table by pasting this code... I don't know anything about biology so this data might be laughable, but its based on your original question: http://stackoverflow.com/questions/33402831/

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread David Blomstrom
I think I answered my question @ http://www.the-art-of-web.com/sql/lookup-table/ It sounds like the field taxon_id is similar to the field id - it's just automatically populated by a numerical key. So if I add a new taxon on row 5, then the taxon_id for the following row with change from 5 to 6 -

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread David Blomstrom
Sorry, I don't think I specified that at the beginning. My original/master table has several fields, four of which are relevant to this hierarchical stuff - id, taxon, parent, parent_id. The first is a numerical key, from 1 to probably somewhere around 8,000 for mammals, 1 to 10,000 for birds, et

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Rob Sargent
On 10/30/2015 04:55 PM, David Blomstrom wrote: The field descr would presumably hold the values I originally had in the field Taxon - e.g. the names of various taxons, like 'Mammalia' and 'Canis-lupus.' The field id is just a numerical key, and I already have the numerical values for parentid.

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Rob Sargent
On 10/30/2015 04:55 PM, David Blomstrom wrote: The field descr would presumably hold the values I originally had in the field Taxon - e.g. the names of various taxons, like 'Mammalia' and 'Canis-lupus.' The field id is just a numerical key, and I already have the numerical values for parentid.

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread David Blomstrom
The field descr would presumably hold the values I originally had in the field Taxon - e.g. the names of various taxons, like 'Mammalia' and 'Canis-lupus.' The field id is just a numerical key, and I already have the numerical values for parentid. But what am I supposed to put in the field taxoni

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread David Blomstrom
Yes, I guess it does make sense to keep a copy of your actions. In the meantime, I now have two new tables with the following schema: -- Table: public.taxon -- DROP TABLE public.taxon; CREATE TABLE public.taxon ( taxonid integer NOT NULL DEFAULT nextval('taxon_taxonid_seq'::regclass), descr

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Rob Sargent
On 10/30/2015 04:38 PM, David Blomstrom wrote: Ah, yes - "Execute SQL." It created the table this time. Awesome. One other question - when I close the SQL window, it asks me if I want to save the file. Is there any special reason for saving it? It looks like it simply saved a copy of the query

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread David Blomstrom
Ah, yes - "Execute SQL." It created the table this time. Awesome. One other question - when I close the SQL window, it asks me if I want to save the file. Is there any special reason for saving it? It looks like it simply saved a copy of the query I executed. On Fri, Oct 30, 2015 at 3:36 PM, Adri

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Adrian Klaver
On 10/30/2015 03:29 PM, David Blomstrom wrote: Thanks for the tips. In pgAdmin III, I can create a table step-by-step by choosing Edit > Object > New Table But is there a pace for me to past in a block of code that creates the table with just one process? If I click on the SQL icon, a SQL windo

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Raymond O'Donnell
On 30/10/2015 22:29, David Blomstrom wrote: > Thanks for the tips. > > In pgAdmin III, I can create a table step-by-step by choosing Edit > > Object > New Table > > But is there a pace for me to past in a block of code that creates the > table with just one process? If I click on the SQL icon, a

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread David Blomstrom
Thanks for the tips. In pgAdmin III, I can create a table step-by-step by choosing Edit > Object > New Table But is there a pace for me to past in a block of code that creates the table with just one process? If I click on the SQL icon, a SQL window opens up, and I can past the code into SQL Edit

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Raymond O'Donnell
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 >

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Rob Sargent
On 10/30/2015 04:10 PM, 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 integ

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Rob Sargent
On 10/30/2015 04:10 PM, 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 integ

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread David Blomstrom
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

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Andy Colson
On 10/30/2015 4:36 PM, Andy Colson wrote: On 10/30/2015 3:47 PM, David Blomstrom wrote: 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' w

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Andy Colson
On 10/30/2015 3:47 PM, David Blomstrom wrote: 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 th

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Andy Colson
On 10/29/2015 7:18 PM, David Blomstrom wrote: Can anyone tell me how to write the query described @ http://stackoverflow.com/questions/33402831/count-descendants-in-hierarchical-query ? The answer's very thorough, but I don't know how to string two queries and a function together like that. This

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread David Blomstrom
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'

Re: [GENERAL] Hierarchical Query Question (PHP)

2015-10-30 Thread Jason O'Donnell
David, Does wrapping the transaction with BEGIN; COMMIT; work as you would expect? $sql = "BEGIN; with recursive hier(taxon,parent_id) as ( select m.taxon, null::integer from gz_life_mammals m where taxon='Mammalia' --<< substitute me union all select m.taxon, m.parent_id from hier,

[GENERAL] Hierarchical Query Question (PHP)

2015-10-29 Thread David Blomstrom
Can anyone tell me how to write the query described @ http://stackoverflow.com/questions/33402831/count-descendants-in-hierarchical-query ? The answer's very thorough, but I don't know how to string two queries and a function together like that. This doesn't work: $sql = "select * from gz_life_ma