LibPQ.jl
LibPQ.jl copied to clipboard
Parsing array of strings?
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?
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)
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!
I think the patterns I have seen that need escaping are {, ,, }, and depending how it is implemented ".