LibPQ.jl icon indicating copy to clipboard operation
LibPQ.jl copied to clipboard

Parsing array of strings?

Open galenlynch opened this issue 6 years ago • 3 comments
trafficstars

I would like to use queries that return arrays of text, however parsing these columns into arrays does not currently work: I just get the string representing the PostgreSQL array instead. I also don't know how to extend the current array parsing code to work with arrays of strings, because there is no entry in _DEFAULT_TYPE_MAP for :text. I am currently trying to figure out how columns of text are normally converted, so I can make this work. Any pointers?

galenlynch avatar May 13 '19 15:05 galenlynch

The reason there's no entry for text is that it uses the default, which just parses it as a string. The existing numeric array parsing code cannot work for arrays of strings as it doesn't expect quotes and there are special parsing rules for quotes. The current parsing code is very simple as I am not particularly experienced with parsing.

postgres=# SELECT '{''foo''}'::text[];
  text
---------
 {'foo'}
(1 row)

postgres=# SELECT '{''foo\{''}'::text[];
    text
------------
 {"'foo{'"}
(1 row)

iamed2 avatar May 13 '19 15:05 iamed2

Yikes, that looks thorny. Ok I'll just do something locally which works if there are no quotes, because that's true for my data. Thank you!

galenlynch avatar May 13 '19 15:05 galenlynch

I think the patterns I have seen that need escaping are {, ,, }, and depending how it is implemented ".

Nosferican avatar Oct 15 '20 20:10 Nosferican