Re: push array to array

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tjibbe Rijpma <tjibbe(at)rijpma(dot)org>
Cc: PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: push array to array
Date: 2016-09-18 17:17:23
Message-ID: CAFj8pRBW_EGXVkp4_+1LqsrHjZ88UD_5xB-9BHHXGj5V-5WkRQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2016-09-18 19:15 GMT+02:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

>
>
> 2016-09-18 19:12 GMT+02:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
>
>> Hi
>>
>>
>> 2016-09-18 18:46 GMT+02:00 Tjibbe <tjibbe(at)rijpma(dot)org>:
>>
>>> '{{4,5},{8,3}}' + '{3,6}'
>>
>>
>> postgres=# select '{{4,5},{8,3}}'::int[] || ARRAY[[3,6]];
>> +---------------------+
>> | ?column? |
>> +---------------------+
>> | {{4,5},{8,3},{3,6}} |
>> +---------------------+
>> (1 row)
>>
>
> CREATE OR REPLACE FUNCTION public.array2d_append(integer[], integer[])
> RETURNS integer[]
> LANGUAGE sql
> AS $function$
> SELECT COALESCE($1 || ARRAY[$2], $1, $2);
> $function$
>

sorry

better

SELECT COALESCE($1 || ARRAY[$2], $1, ARRAY[$2]);

>
> postgres=# SELECT array2d_append('{{4,5},{8,3}}', '{3,6}');
> +---------------------+
> | array2d_append |
> +---------------------+
> | {{4,5},{8,3},{3,6}} |
> +---------------------+
> (1 row)
>
>
>
>>
>> regards
>>
>> Pavel
>>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Patrick B 2016-09-18 21:18:47 select distinct postgres 9.2
Previous Message Pavel Stehule 2016-09-18 17:15:59 Re: push array to array