Say I have the following psuedo-schema, where the 1-many
relation is modeled using Postgres arrays :
CREATE TYPE quotes AS
(
text CHARACTER VARYING,
is_direct CHARACTER VARYING
);
CREATE TABLE posts
(
body CHARACTER VARYING,
q quotes[]
);
insert into posts(body,q) VALUES('ninjas rock',ARRAY[ ROW('I AGREE',True)::quotes, ROW('I DISAGREE',FALSE)::quotes ]);
My first question is: how do I perform a select to filter out the quote->text
from the entire array.
This works :
test=# select body, q[1].text from posts;
body | text
--------------+---------
hassan rocks | I AGREE
(1 row)
But this doesn't (note that the entire composite type is being retrieved) :
test=# select body, (q).text from posts;
body | text
--------------+-------------------------------------------------
hassan rocks | {"(\"I AGREE\",true)","(\"I DISAGREE\",false)"}
(1 row)
To bridge onto my real question, how would I create a gin or gist (with or without to_tsvector
) index which includes the text of both the post body as well as all of the quote text ? I Prefer not to go with the extra column approach of indexing as triggers make me sad.
Currently my schema represents the post and quote as a 1-many
relation, however I think if postgres supports what I am trying to do it would simplify things drastically.