Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postgresql array #29

Closed
Skarsnik opened this issue Nov 11, 2015 · 10 comments
Closed

Add postgresql array #29

Skarsnik opened this issue Nov 11, 2015 · 10 comments
Assignees

Comments

@Skarsnik
Copy link
Contributor

Could be cool to have pg_array support, meaning fetch* should return an array for the array field and execute be able to work on array value.

Basicly it probably converting array string pg give us, they look like that: {NonSpace, "With Space"} and can be nested {{value, value}, {value, value}}

@azawawi
Copy link
Contributor

azawawi commented Nov 11, 2015

Could you provide a sample usage scenario (i.e actual code snippet)?

@moritz
Copy link
Contributor

moritz commented Nov 12, 2015

I think I've changed my opinion here, and now posit that it's not DBIish's job to parse such values.

The Postgres C client library returns them as strings, so DBIish should return them as string too. If you want something that maps them to a more advanced data types (arrays to arrays, hstore to hashes, jsonb to arrays/hashes/strings/numbers/...), that belongs into an ORM.

If you disagree, please explain why it's DBIish's job.

@Skarsnik
Copy link
Contributor Author

Well first DBI in perl5 does it. Array is a supported type defined in the SQL99 RFC. it's probably not only supported in Pg http://savage.net.au/SQL/sql-99.bnf.html#array specification
I did not find the documentation of the Pg library but there is maybe some call that handle array
At least if you don't want a full support in DBIsh, providing a serialize/deserialize method somewhere could still be useful :)

@moritz
Copy link
Contributor

moritz commented Nov 12, 2015

Oh, I didn't know it was part of the SQL standard. If there's a way in which Postgres indicates that it's returning an array, I'm fine with it being implemented in DBIish after all.

Still, (de)serialization in general belongs into layer about DBIish, because it requires more meta information about the data types being used/returned.

@azawawi
Copy link
Contributor

azawawi commented Nov 12, 2015

Actually our mapping is not 100% correct as far as I can see, please take a look at pg_type.h. Namely this:

#define     INT2ARRAYOID     1005
#define     INT4ARRAYOID     1007
#define     TEXTARRAYOID     1009
#define     OIDARRAYOID      1028
#define     FLOAT4ARRAYOID   1021
#define     CSTRINGARRAYOID  1263

and PostgreSQL documentation on Arrays

I am going to work on this one for the rest of the evening 👍

@azawawi azawawi self-assigned this Nov 12, 2015
@azawawi
Copy link
Contributor

azawawi commented Nov 16, 2015

Initial implementation added in my forked repository. Please review https://github.com/azawawi/DBIish/commit/87d311f0e55052f067bba45ff53c4f938277dee3.

@Skarsnik
Copy link
Contributor Author

Thanks for you work.
I merged you modification into the current DBIish. I will close this ticket when tests will be added, if someone feel like doing so x)

@salortiz
Copy link
Contributor

@azawawi What is the status of the offered tests?

@salortiz
Copy link
Contributor

salortiz commented Mar 7, 2016

Reworked a little the array engine and now pass the test provided by @Skarsnik

@salortiz salortiz closed this as completed Mar 7, 2016
@azawawi
Copy link
Contributor

azawawi commented Mar 7, 2016

@salortiz Thanks for the fix. I am very sorry but I was busy doing other projects and forgot about this issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants