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

Non-numeric arrays support

Open aplavin opened this issue 6 years ago • 5 comments

Hi! Is it possible to automatically convert postgres arrays to julia arrays? E.g. when there is array_agg in the query.

aplavin avatar Dec 06 '18 09:12 aplavin

Yes, and this should already work; please give me examples where it doesn't and I will attempt to fix any issues :)

iamed2 avatar Dec 06 '18 16:12 iamed2

@iamed2 well, here is a very simple reproducible example:

fetch!(NamedTuple, execute(conn, "
select array_agg(schemaname)
from pg_tables
")).array_agg[1]

gives a string, which in my case looks like this:

"{public,public,public,pg_catalog,pg_catalog,public,public,public,public,public,public,public,public,public,public,public,pg_catalog,pg_catalog,pg_catalog,public,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,pg_catalog,information_schema,information_schema,information_schema,information_schema,information_schema,information_schema,information_schema,pg_catalog,public,public,public,public,public}"

instead of an array of strings.

And now, after looking into LibPQ.jl code, I see that numeric arrays are supported. However, string- and other are not, right?

aplavin avatar Dec 06 '18 16:12 aplavin

I've changed the title; currently I support numeric arrays only. I need to add escaping support in order to support text.

iamed2 avatar Dec 06 '18 18:12 iamed2

That would be useful indeed. I'm not familiar with the postgres api, does it just return everything as strings and you parse them into whatever datatype?

aplavin avatar Dec 06 '18 18:12 aplavin

Yes, if you use the text format, which I do right now. Lines 268-346 in src/parsing.jl contain the current code for parsing numeric arrays, if you're interested in making a PR.

iamed2 avatar Dec 06 '18 19:12 iamed2