From: | Ibrahim Shaame <ishaame(at)gmail(dot)com> |
---|---|
To: | Tomek <tomekphotos(at)gmail(dot)com> |
Cc: | pgsql-novice(at)lists(dot)postgresql(dot)org |
Subject: | Re: reporting tree into separate columns |
Date: | 2023-11-26 18:18:42 |
Message-ID: | CAJOWwD7fnwOzw7rJG=u8RQXg8ghhX=cepOatmVX9ocX4i5AYjg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Thanks for the response :
...... insert values to proper place in array instead of building
concatenated string separated with ' - '
Any proposal for it. Because there I have not succeeded.
On Sun, Nov 26, 2023 at 2:33 PM Tomek <tomekphotos(at)gmail(dot)com> wrote:
> Now you can use regexp_split_to_array
> Look like it works:
> select (regexp_split_to_array('Asia Khamis Haji - Ishak Makame Haji -
> Ibrahim Ishak Makame', '-'))[1]
> , (regexp_split_to_array('Asia Khamis Haji - Ishak Makame Haji - Ibrahim
> Ishak Makame', '-'))[2]
> , (regexp_split_to_array('Asia Khamis Haji - Ishak Makame Haji - Ibrahim
> Ishak Makame', '-'))[3]
> , (regexp_split_to_array('Asia Khamis Haji - Ishak Makame Haji - Ibrahim
> Ishak Makame', '-'))[4]
>
> Or from the beginning in your CTE insert values to proper place in array
> instead of building concatenated string separated with ' - '
>
> Regards Tomek
> (szaman)
>
> sob., 25 lis 2023 o 08:40 Ibrahim Shaame <ishaame(at)gmail(dot)com> napisał(a):
>
>> I have the following query which gives me family tree
>>
>> with recursive x (jina,namba,nasaba_1)
>>
>> as (
>>
>> select jina ||' '|| baba ||' '|| babu AS jina,namba, nasaba_1
>>
>> from majina2
>>
>> where nasaba_1 = 0
>>
>> union all
>>
>> select x.jina ||' '|| ' - '|| e.jina || ' ' || baba || ' ' || babu,
>> e.namba, e.nasaba_1
>>
>> from majina2 e, x
>>
>> where e.nasaba_1 = x.namba
>>
>> )
>>
>> select
>> jina,namba,nasaba_1,(length(jina)-length(replace(jina,'-','')))/length('-')
>> AS depth
>>
>> from x
>>
>> order by 1;
>>
>>
>> And I get the following result:
>>
>>
>> jina namba Nasaba_1 depth
>> Asia Khamis Haji 100002 0 0
>> Asia Khamis Haji - Azida Makame Haji 100128 100002 1
>> Asia Khamis Haji - Ishak Makame Haji 100127 100002 1
>> Asia Khamis Haji - Ishak Makame Haji - Alia Ishak Makame 100250 100127 2
>> Asia Khamis Haji - Ishak Makame Haji - Ibrahim Ishak Makame 100251 100127
>> 2
>> Asia Khamis Haji - Khamis Abdalla Ali 100126 100002 1
>> Asia Khamis Haji - Mwajuma Abdalla 100125 100002 1
>> Asia Khamis Haji - Namwira Abdalla Mosi 100124 100002 1
>>
>>
>> But what I want to get is to report the first column in different columns
>> according to depth (last column)
>>
>>
>> Any suggestions
>>
>>
>> Thanks
>>
>> Ibrahim Shaame
>>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Al Wilson | 2024-01-03 17:03:51 | Vulnerability remediation |
Previous Message | Tomek | 2023-11-26 11:33:41 | Re: reporting tree into separate columns |