ruby-pg icon indicating copy to clipboard operation
ruby-pg copied to clipboard

Q: Is it possible to handle composite values like `row(123, 'str', true)` ?

Open kwatch opened this issue 6 months ago • 1 comments

Is it possible to retrieve composite values (ex: row(123, 'str', true, null)) as Ruby's Array object (ex: [123, "str", true, nil]) ?

I hope to execute the following SQL...

select row(emp.*), row(dept.*)    --- !!! composite values !!!
from employees as emp
join departments as dept on emp.dept_id = dept.id

and want to get the following result for example...

[
  [1001, "Alice",    211, "Sales"],
  [1002, "Bob",      215, "Marketing"],
  [1003, "Charlie",  213, "Customer support"],
]

but actually got the following unexpected result:

[
  ["(1001,\"Alice\",211,\"Sales\")"],
  ["(1002,\"Bob\",215,\"Marketing\")"],
  ["(1003,\"Charlie\",215,\"Customer support\")"],
]

If you know how to retrieve composite values correctly, please let me know.

(I found the following page but I can't succeeded to do what I want.) https://deveiate.org/code/pg/PG/TextDecoder/Record.html

kwatch avatar Aug 10 '24 02:08 kwatch