{"action":"created","issue":{"url":"https://api.github.com/repos/pgjdbc/pgjdbc/issues/396","labels_url":"https://api.github.com/repos/pgjdbc/pgjdbc/issues/396/labels{/name}","comments_url":"https://api.github.com/repos/pgjdbc/pgjdbc/issues/396/comments","events_url":"https://api.github.com/repos/pgjdbc/pgjdbc/issues/396/events","html_url":"https://github.com/pgjdbc/pgjdbc/issues/396","id":110992986,"number":396,"title":"Subpar/Dangerous/Undocumented Array support in prepared statements","user":{"login":"RomanHargrave","id":6024227,"avatar_url":"https://avatars.githubusercontent.com/u/6024227?v=3","gravatar_id":"","url":"https://api.github.com/users/RomanHargrave","html_url":"https://github.com/RomanHargrave","followers_url":"https://api.github.com/users/RomanHargrave/followers","following_url":"https://api.github.com/users/RomanHargrave/following{/other_user}","gists_url":"https://api.github.com/users/RomanHargrave/gists{/gist_id}","starred_url":"https://api.github.com/users/RomanHargrave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RomanHargrave/subscriptions","organizations_url":"https://api.github.com/users/RomanHargrave/orgs","repos_url":"https://api.github.com/users/RomanHargrave/repos","events_url":"https://api.github.com/users/RomanHargrave/events{/privacy}","received_events_url":"https://api.github.com/users/RomanHargrave/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-10-12T15:03:09Z","updated_at":"2015-10-19T19:41:24Z","closed_at":null,"body":"As it currently stands, array support is extremely lacking, and relies on an unenforced contract for the return value of `toString()`. When a prepared statement object is given an array (specifically, an implementation of `java.sql.Array`), it will only call one of the `java.sql.Array` contract functions (`getBaseTypeName`) to get the array type name, to which it will then append `[]`. It will then use this newly constructed array type literal to find a type OID. As an aside, this appears to be somewhat broken, providing strange error messages that purport the type to be nonexistent when given builtin types, such as `INT`, or `INTEGER` (of which `INT` is an alias). After doing this, it then ***calls `toString()` on the object*** and adds the return value to the statement.\r\n\r\nThis is an _incredibly_ bad idea, for a number of reasons. Firstly, `toString()` should return a more descriptive value _of the object instance_, and secondly, could have some seriously frustrating and time consuming implications for developers trying to add an array (especially a complex array) to a statement.\r\n\r\nThe offending code is contained in [the method `setArray()` on line 3020 of `AbstractJdbc2Statement.java`](https://github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/jdbc2/AbstractJdbc2Statement.java#L3020), and has been _stagnant_ for roughly _eleven_ years to date, with the exception of some minor duct taping in of binary array support in 2011 and a modification to the type lookup in 2015.\r\n\r\nCurrently, it would be more practical for most developers to simply re-implement array support on their own, using PGobject, than it would be for them to use the drivers native array support, given the level of incompleteness. "},"comment":{"url":"https://api.github.com/repos/pgjdbc/pgjdbc/issues/comments/149323405","html_url":"https://github.com/pgjdbc/pgjdbc/issues/396#issuecomment-149323405","issue_url":"https://api.github.com/repos/pgjdbc/pgjdbc/issues/396","id":149323405,"user":{"login":"vlsi","id":213894,"avatar_url":"https://avatars.githubusercontent.com/u/213894?v=3","gravatar_id":"","url":"https://api.github.com/users/vlsi","html_url":"https://github.com/vlsi","followers_url":"https://api.github.com/users/vlsi/followers","following_url":"https://api.github.com/users/vlsi/following{/other_user}","gists_url":"https://api.github.com/users/vlsi/gists{/gist_id}","starred_url":"https://api.github.com/users/vlsi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vlsi/subscriptions","organizations_url":"https://api.github.com/users/vlsi/orgs","repos_url":"https://api.github.com/users/vlsi/repos","events_url":"https://api.github.com/users/vlsi/events{/privacy}","received_events_url":"https://api.github.com/users/vlsi/received_events","type":"User","site_admin":false},"created_at":"2015-10-19T19:41:24Z","updated_at":"2015-10-19T19:41:24Z","body":"I meant to close #396 as it apparently has less comments"}}