Is it possible to delete a Postgres array element by index? (Using Postgres 9.3.)
I don't see anything for this in the docs (http://www.postgresql.org/docs/9.3/static/functions-array.html) but perhaps there are other functions I am missing?
Is it possible to delete a Postgres array element by index? (Using Postgres 9.3.) I don't see anything for this in the docs (http://www.postgresql.org/docs/9.3/static/functions-array.html) but perhaps there are other functions I am missing? |
|||||
|
There is no built-in function that I would know of. In Postgres 9.3+ you have the silimar function
Say, you have a 1-dimenstional array If array elements are unique, you can:
If uniqueness is not guaranteed the above might delete multiple elements. You can concat two array slices instead:
2147483647 is just the maximum possible array subscript to cover all possibilities. Works for any version since at least 8.3, probably more. If you need this a lot, create a function. I suggest an
Call:
Result:
It would be more complicated:
|
|||||||||
|