Re: join of array

From: elein <elein(at)varlena(dot)com>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>, pgsql-general(at)postgresql(dot)org
Subject: Re: join of array
Date: 2003-08-15 16:54:43
Message-ID: 20030815095443.C22348@cookie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-patches

>
> ARRAY[[1,2],[3,4]] || ARRAY[[1,2],[3,4]] ==
> '{{{1,2},{3,4}},{{1,2},{3,4}}}'
>
> I think the first two still make sense. I guess the third case ought to be:
> ARRAY[[1,2],[3,4]] || ARRAY[[1,2],[3,4]] ==
> '{{1,2},{3,4},{1,2},{3,4}}'
> ?

I do not think this is right. I think the current behaviour
is right. You are effectively dereferencing or flattening
the second array which changes the definition of the second
object.

The ability to do the dereference/flattening is useful,
but it is not the || operator. How about |* which would
flatten 1 level? Of course, that begs the question
of what about n levels and I'm not sure about that.

--elein

On Fri, Aug 15, 2003 at 08:34:14AM -0700, Joe Conway wrote:
> Tom Lane wrote:
> >Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz> writes:
> >
> >>Is possible merge two arrays like
> >>array[1,2,3] + array[4,5,6] => array[1,2,3,4,5,6]
> >
> >
> >I was about to say that || would do it, but I see that's not quite
> >right:
> >
> >regression=# SELECT ARRAY[1,2,3] || ARRAY[4,5,6];
> > ?column?
> >-------------------
> > {{1,2,3},{4,5,6}}
> >(1 row)
> >
> >Offhand, I would think that '{1,2,3,4,5,6}' would be what I'd
> >intuitively expect to get from "concatenating" these arrays.
> >Joe, do we really have this implemented per spec?
> >
>
> Hmmm, it made sense to me, at at least at some point ;-). Here's the
> SQL99 guidance (SQL200X doesn't give any more detailed guidance):
>
> 4.11.3.2 Operators that operate on array values and return array values
> <array concatenation> is an operation that returns the array value made
> by joining its array value operands in the order given.
>
> So I guess it ought to be changed.
>
> We also have
> ARRAY[1,2] || 3 == '{1,2,3}'
> and
> ARRAY[[1,2],[3,4]] || ARRAY[5,6] == '{{1,2},{3,4},{5,6}}'
> and
> ARRAY[[1,2],[3,4]] || ARRAY[[1,2],[3,4]] ==
> '{{{1,2},{3,4}},{{1,2},{3,4}}}'
>
> I think the first two still make sense. I guess the third case ought to be:
> ARRAY[[1,2],[3,4]] || ARRAY[[1,2],[3,4]] ==
> '{{1,2},{3,4},{1,2},{3,4}}'
> ?
>
> If this sounds good, I'll work on a patch for the behavior as well as
> the docs.
>
> Joe
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2003-08-15 16:57:24 Re: importing db as text files
Previous Message Stephan Szabo 2003-08-15 16:53:05 Re: [GENERAL] 7.4Beta

Browse pgsql-patches by date

  From Date Subject
Next Message Joe Conway 2003-08-15 17:06:36 Re: join of array
Previous Message Guillaume LELARGE 2003-08-15 16:00:29 NLS: French .po files updated