Re: Sorting CSV string and removing Duplicates
От | Alex Magnum |
---|---|
Тема | Re: Sorting CSV string and removing Duplicates |
Дата | |
Msg-id | CA+cR4zdgkNk_fM-YSyNKeUKB5HUKhc_QvfuHKwJito9=JEUGnQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Sorting CSV string and removing Duplicates (dinesh kumar <dineshkumar02@gmail.com>) |
Список | pgsql-general |
Hi Danish, yes thats the one I was looking for. Thanks a lot!!!
On Tue, Jul 28, 2015 at 1:32 AM, dinesh kumar <dineshkumar02@gmail.com> wrote:
On Mon, Jul 27, 2015 at 12:57 PM, dinesh kumar <dineshkumar02@gmail.com> wrote:On Mon, Jul 27, 2015 at 12:53 PM, Alex Magnum <magnum11200@gmail.com> wrote:Hello,I have a csv string in a text field that is unsorted and contains duplicates.Is there a simple way to remove these and sort the string.E.g2,18,20,23,1,27,1,2,8,16,17,18,20,22,23,27i tried string to array and unique but that did not work...Any suggestions on how to do this without writing a function?Any help is appreciated.Are you looking for this.postgres=# SELECT unnest(string_to_array(t, ',')) from test group by 1;unnest--------21882022162717231(10 rows)ORMight be something like thispostgres=# WITH sortedstring aspostgres-# (postgres(# SELECT unnest(string_to_array(t, ','))::int from test group by 1 ORDER BY 1postgres(# ) SELECT array_agg(unnest) FROM sortedstring;array_agg------------------------------{1,2,8,16,17,18,20,22,23,27}(1 row)Regards,
Dinesh
В списке pgsql-general по дате отправления: