2

In my nodeJs application I need to store and retrieve nested arrays that represents coordinates of features geometry (point, lines, polygon) but not in a format usually used by postgis.

For instance the arrays would look like this:

[[0, 0, 0, 1, 0, 2, ...], [1, 0, 1, 1, 1, 2, ...], ...]

or conceptually:

[[x0, y0, x1, y1, x2, y2, ...], [x0, y0, x1, y1, x2, y2, ...], ...]

I dont want to transform those arrays into a postgis geom structure.

I want to be able to store and retrieve thoses arrays in the simplest way.

What postgres column type would you suggest?

Edit: those arrays could be large

Edit2: In the example above, the numbers are small int but in reality they would be float

8
  • 1
    longtext, but convert your array to json prior to storing it, and unconvert it on retrieval Commented Sep 1, 2015 at 19:21
  • What would be the actual range and type of the numbers? Simple small integers like demonstrated or something else, really? Would all nested arrays strictly share the same number of elements? Commented Sep 1, 2015 at 21:37
  • Just use YouType[][], it's easy to search through and process within Postgres. Commented Sep 1, 2015 at 23:43
  • @ErwinBrandstetter in fact the numbers would be float Commented Sep 2, 2015 at 11:54
  • You missed my 2nd (important) question. Postgres arrays require matching length for all array dimensions. Commented Sep 2, 2015 at 13:34

1 Answer 1

3

Use text.

Really, if you're not going to manipulate them in the database (eg search by coordinates) text will be smaller (and compress better), and easier to work with than either json/jsonb or SQL arrays (which can be multidimensional, just for the record).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.