#31450: Querying on ArrayField(PointField) returns string instead of list
-------------------------------------+-------------------------------------
     Reporter:  Nitin Sangwan        |                    Owner:  Hasan
                                     |  Ramezani
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.postgres     |                  Version:  3.0
     Severity:  Normal               |               Resolution:
     Keywords:  ArrayField,          |             Triage Stage:  Accepted
  PointField                         |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Hasan Ramezani):

 Comment from the PR:

 Thanks @Simon for your suggestion.
 I've tried to create and register a new array type for `geometry` based on
 your suggestion at #8453. here is the code:


 {{{

 def get_geometry_oids(connection_alias):
     with connections[connection_alias].cursor() as cursor:
         cursor.execute("SELECT typarray FROM pg_type WHERE typname =
 'geometry'")
         return tuple(row[0] for row in cursor)

 ...

        geometry_oids = get_geometry_oids(connection.alias)
         new_type = psycopg2.extensions.new_type(geometry_oids, "geometry",
 caster) # caster is function to cast hex to geometry object
         array_type = psycopg2.extensions.new_array_type(geometry_oids,
 'geometry[]', new_type)
         psycopg2.extensions.register_type(array_type, None)

 }}}

 The problem is that in `caster` function, I get all items in array not one
 item. something like this:
 
`0101000020E610000000000000000018400000000000003840:0101000020E610000000000000000014400000000000003740`
 which is represent two points that seprated by `:`.
 I've checed the column value in postgres console. for an array of points I
 got this:
 
`{0101000020E6100000000000000000F03F0000000000000040:0101000020E6100000000000000000F03F0000000000000040}`
 While, I got below value for an array of chars:
 `{foo,bar}`

 the difference between two cases is for an array of points I got `:` as a
 separator,  but for an array of chars I got `,`.

 I also tried to insert data from console to an array of points column by:
 `insert into test values (ARRAY[st_geomFromText('POINT(1 1)', 4326),
 st_geomFromText('POINT(1 1)', 4326)]);`
 the result was the same(`:` as separator).

 Do you have any idea?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31450#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.e8ce9431964236d0ca09f6ad8bdb7f6a%40djangoproject.com.

Reply via email to