Re: PL/Python adding support for multi-dimensional arrays - Mailing list pgsql-hackers

From Jim Nasby
Subject Re: PL/Python adding support for multi-dimensional arrays
Date
Msg-id 315d98b5-ca4b-9d37-d23f-af19eb85fdf5@BlueTreble.com
Whole thread Raw
In response to Re: PL/Python adding support for multi-dimensional arrays  (Heikki Linnakangas <hlinnaka@iki.fi>)
Responses Re: PL/Python adding support for multi-dimensional arrays  (Michael Paquier <michael.paquier@gmail.com>)
Re: PL/Python adding support for multi-dimensional arrays  (Heikki Linnakangas <hlinnaka@iki.fi>)
List pgsql-hackers
On 9/29/16 1:51 PM, Heikki Linnakangas wrote:
> Jim, I was confused, but you agreed with me. Were you also confused, or
> am I missing something?

I was confused by inputs:

CREATE FUNCTION repr(i foo[]) RETURNS text LANGUAGE plpythonu AS 
$$return repr(i)$$;
select repr(array[row(1,2)::foo, row(3,4)::foo]);        repr
-------------------- ['(1,2)', '(3,4)']
(1 row)

(in ipython...)

In [1]: i=['(1,2)', '(3,4)']

In [2]: type(i)
Out[2]: list

In [3]: type(i[0])
Out[3]: str

I wonder if your examples work only

> Now, back to multi-dimensional arrays. I can see that the Sequence
> representation is problematic, with arrays, because if you have a python
> list of lists, like [[1, 2]], it's not immediately clear if that's a
> one-dimensional array of tuples, or two-dimensional array of integers.
> Then again, we do have the type definitions available. So is it really
> ambiguous?

[[1,2]] is a list of lists...
In [4]: b=[[1,2]]

In [5]: type(b)
Out[5]: list

In [6]: type(b[0])
Out[6]: list

If you want a list of tuples...
In [7]: c=[(1,2)]

In [8]: type(c)
Out[8]: list

In [9]: type(c[0])
Out[9]: tuple
-- 
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)   mobile: 512-569-9461



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Show hash / bitmap sizes in EXPLAIN ANALYZE?
Next
From: Andres Freund
Date:
Subject: Re: Macro customizable hashtable / bitmapscan & aggregation perf