Select rows in a PostgreSQL array

1

I'm using the PostgreSQL and Python database to query it, I have the following modeling:

I'mtryingtomakeaquerythatreturnsallOrderItemsofaOrdertoaarray,forthisImadethefollowingcode:

selectARRAY(SELECT'('||translate(string_to_array(x.*::"text", ',')::text, '{()}', '') || ')' 
    from "OrderItem" x
)::"OrderItem"[] AS "_AAA";

What returns me the following result:

"{"(16,1,ProductName1,M,45.00,1,6)","(17,6,ProductName2,M,45.00,1,6)"}"

In Python I'm using psycopg2 to talk to the database, and so it returns me a string, just like in the above result, not being able to iterate through it to get the tuples with the values.

Does anyone have any idea how I can do this query to return an array of OrderItem?

    
asked by anonymous 11.12.2014 / 20:57

1 answer

1

It seems like you want to aggregate the rows of the table orderItem

select array_agg(orderItem) as "_AAA"
from orderItem
where orderId = 10

This should return a list of tuples.

link

    
13.12.2014 / 09:21