Re: join of array - Mailing list pgsql-general

From elein
Subject Re: join of array
Date
Msg-id 20030815095443.C22348@cookie
Whole thread Raw
In response to Re: join of array  (Joe Conway <mail@joeconway.com>)
Responses Re: join of array  (Joe Conway <mail@joeconway.com>)
List pgsql-general
>
>   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@kix.fsv.cvut.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
>

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: importing db as text files
Next
From: Jenny Zhang
Date:
Subject: getting execution plans with multiple database connections