I've looked on some recursive queries here, but haven't found my problem. In addition to that I'm new to postgreSQL.
I have the following table with example data:
number numberto ab st kz pv
112 200
140 210
200 210
210 220 f2 140 H 2011
220 f2 140 H 2011
The query will be a bit more complicated, but this is the part I can't solve. numberto
refers to another number
and then maybe again. I can be that this chain continues about four or five times.
Some day the other four coloumns are then NOT NULL
and filled with letters and/or numbers. If ab has content, then the other three will have it too. If the last coloumns are filled, numberto
can refer further, but will remain the same, so it's able to stop there.
My problem: I need to make a recursive query of one number, that then searches numberto
as many times as needed until e.g. ab
is then filled and get an output of them.
How can I achieve this?
SELECT version();
PostgreSQL 9.2.6 on x86_64-unknown-linux-gnu, compiled by gcc (SUSE Linux) 4.3.4 [gcc-4_3-branch revision 152973], 64-bit