5 ms·
> Or if you're using Postgres, you can return the metadata as an associative array. E.G. http://stackoverflow.com/a/11942726 http://stackoverflow.com/a/11942726
by yangyang 12y ago
> Or if you're using Postgres, you can return the metadata as an associative array. E.G. http://stackoverflow.com/a/11942726 http://stackoverflow.com/a/11942726
That's not an associative array, it's just an array of a composite type. The hstore type is probably the closest you'd get to an associate array in PostgreSQL, but the keys and values are always strings.
- jimktrains2 12y agoIt's returning a record, which is more of a struct than an array.
- yangyang 12y agoCREATE OR REPLACE FUNCTION get_people() RETURNS person[] LANGUAGE sql AS person is a composite type, defined further up. The square brackets indicate an array of that type.
- jimktrains2 12y agoI misread you at first.
- dragonwriter 12y ago> The hstore type is probably the closest you'd get to an associate array in PostgreSQL No, a table (possibly a temp table with the results of a particular query) with an appropriately defined primary key (or other unique index) would be the closest you can get to an associative array -- since a relation with n candidate keys is exactly identical to n different associative arrays with the same data but different key/value splits. But an array of a composite type drawn in such a way that some set of columns is guaranteed unique is pretty much the same thing from a data perspective, even though you may need to do work on the client side to load it into a structure that supports associative array operations (e.g., efficient key/value lookups).
- yangyang 12y agoI meant as a self-contained type. PostgreSQL doesn't support nested tables. The "associative" in associative array implies association is a property of the data structure, not the way you happen to be using it.