Pg-promise: QUESTION: Result as an associative array?

Created on 18 Sep 2019  路  4Comments  路  Source: vitaly-t/pg-promise

Is there support to receive a result as an associative array or a result set as an array of associative arrays? I have searched Google and GitHub without finding references to this, so I am assuming not, but just checking in case.

question

All 4 comments

Sorry, I can rephrase: Can pg-promise return a result set as an array of objects where the property names are the column names?

eg:

[{
    "name": "Joe",
    "age": 20
}, {
    "name": "Mike",
    "age": 25
}]

I use the term associative array because everything in Javascript is an associative array, even an object. Also because the common PHP/MySQL makes heavy use of associative arrays, so it might have been an easier reference point to related to for some.

Wikipedia "In JavaScript an object is a mapping from property names to values鈥攖hat is, an associative array "
https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(associative_array)#JavaScript

"The whole of the JavaScript language is built on one central data structure - the associative array. Objects in JavaScript are just associative arrays and this causes a lot of confusion at first. But the fact of the matter is that the associative array is used to build every other type of data structure in JavaScript."
https://www.i-programmer.info/programming/javascript/1441-javascript-data-structures-the-associative-array.html

My mistake, pg-promise already always returns the query result as an array of objects .

It was just my specific case with a PostgreSQL function that returns a record that wasn't.

Thanks again and sorry for the obvious question.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alpertuna picture alpertuna  路  4Comments

hawkeye64 picture hawkeye64  路  4Comments

paleite picture paleite  路  4Comments

seanh1414 picture seanh1414  路  4Comments

ghost picture ghost  路  3Comments