In my program I have (almost) such a table:
CREATE TEMP TABLE temp_list
(profilenum integer, profilename text, compid text)
ON COMMIT DROP;
INSERT INTO temp_list
VALUES (1, 'bynamePROFILE_border_Minimal', '03'),
(2, 'bynamePROFILE_backoffice_Universal', '03'),
(3, 'bynamePROFILE_calc_Universal', '03'),
(4, 'bynamePROFILE_calc_Universal', '02'),
(5, 'bynamePROFILE_backoffice_Minimal', '01'),
(6, 'bynamePROFILE_ilup_Universal', '03');
I can query it like this:
SELECT profilename
FROM temp_list WHERE compid='03' AND profilename LIKE 'bynamePROFILE_%';
... what gives expected result.
But I need some string manipulation to get wanted strings suitable to lately cast to array form in my program:
SELECT array_agg(btrim(profilename, 'bynamePROFILE_'))
FROM temp_list WHERE compid='03' AND profilename LIKE 'bynamePROFILE_%';
This gives me incorrect result:
"{order_Minimal,ckoffice_Universal,calc_Universal,ilup_Universal}"
(note missing first letter(s) in words beginning with 'b')
instead of:
"{border_Minimal,backoffice_Universal,calc_Universal,ilup_Universal}"
Is this because of me (as usual) or because of PostgreSQL and can my query be improved somehow to get wanted result?
Windows 10/64, PostgreSQL 9.6