Opened 10 years ago

Last modified 23 months ago

#97 assigned enhancement

Array support

Reported by: jtv Owned by: jtv
Priority: high Component: datatypes
Severity: Incomplete Keywords:

Description (last modified by jtv)

Joris van Zwieten requests support for postgres array types.

At the moment arrays can only be manipulated and queried in SQL, or generated and parsed as text. It would be nice to help users get around the latter if we can.

Container and stream interfaces seem the most appropriate. We'd want to be able to construct input arrays from either a field or a string.

There are a few gotchas:

  • Separators between array elements are defined by the contained type. Usually the comma separates elements, but the Box type for example uses a semicolon. It could be anything. We'll have to query that at runtime, and cache the information somehow.
  • Arrays can be nested. We'd probably want to check that all elements are arrays (or nulls) before going into deeper nesting levels.
  • Quoting of array elements may be awkward--we'd have to have separate "treatments" just like we do for prepared statements.
  • How do we specify nulls when creating an array?
  • There is no real "end" to an array: there just comes a point where all else is null. On the C++ end we'd probably want more C++-like semantics, setting end() just past the last non-null element. But what if the last element in an array is null? Programs may break if they hit an unexpected end. We'd need more tolerant semantics: X.end()+1==X.end() and X.end()->is_null()==true.
  • It would be nice to allow direct array indexing in a result ("r[row][col][i]") but it does complicate the result class a bit further.
  • Array lengths aren't enforced by the backend (at least not in 8.2). It's tempting to stick to an array's declared length, but if we do, we must still accept out-of-bounds addressing.

Finally there is the encoding problem in the case of arrays of strings (or arrays of arrays of strings etc.). Parsing a string as an array of strings can go haywire in multibyte encodings that allow byte values equivalent to the closing quote inside a multibyte character. To get around that we'd need to know at least where the character boundaries are--which in turn depends on the encoding being used.

Attachments (0)

Change History (12)

comment:1 Changed 10 years ago by jtv

  • Description modified (diff)
  • Status changed from new to assigned

comment:2 Changed 10 years ago by jtv

  • milestone set to 2.6.10

comment:3 Changed 10 years ago by jtv

  • Description modified (diff)

comment:4 Changed 10 years ago by jtv

  • Description modified (diff)

comment:5 Changed 10 years ago by jtv

  • Description modified (diff)

comment:6 Changed 10 years ago by jtv

  • Description modified (diff)

comment:7 Changed 9 years ago by jtv

  • milestone changed from 2.6.10 to 3.1

comment:8 Changed 7 years ago by jtv

  • milestone 3.1 deleted

comment:9 Changed 7 years ago by jtv

Waiting for libpq to add support.

comment:10 Changed 6 years ago by jtv

  • Severity changed from normal to Incomplete

comment:11 Changed 2 years ago by RichardWef

  • version set to 3.0
Last edited 23 months ago by jtv (previous) (diff)

comment:12 Changed 23 months ago by jtv

  • milestone 3.1 deleted

Milestone 3.1 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
as assigned .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from jtv. Next status will be 'new'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.