I have a table my_friends_cards
:
id | name | rare_cards_composite[] |
---+---------+------------------------
1 | 'timmy' | { {1923, 'baberuth'}, {1999, 'jeter'}}
2 |'jimmy' | { {1955, 'Joey D'}, {1995, 'juice_head'}}
3 |'bob' | {{2001, 'mo_jeter'}}
I want to make the a request kinda like this:
Select name, (cards.x).player
FROM SELECT UNNEST(base_ball_card) as x
FROM my_friends_cards
WHERE name=ANY(['timmy', 'jimmy'])) as cards
WHERE (cards.x).year > 1990
(I know this doesn't work that there is no 'name' field in the unnested composite array.)
I am getting the feeling that my composite type array column should just be another table, and then I could do a join, but is there anyway around this?
I would expect this result:
[('timmy', 'jeter')
,('jimmy', 'juice_head')]
version: PostgreSQL 9.3.3
CREATE TABLE
script with the question. And your version of Postgres (as always). – Vermin