Probably a simple question, but I am unable to translate the SQL to Query API function calls.
I'm using PostgreSQL 11 and SQLAlchemy 1.3.
The raw SQL query I want to translate is this:
SELECT s.post_id, s.signature, count(a.query) AS score
FROM post_signature AS s, unnest(s.words, $1) AS a(word, query)
WHERE a.word = a.query
GROUP BY s.post_id
ORDER BY score DESC LIMIT 100;
I know to start off the query with:
session.query(model.PostSignature)
but I don't understand how to specify the unnest part in the FROM clause, or to then count the unnested values in the SELECT clause.
There's also very little documentation on sa.func.unnest() in the official documentation website. Can anyone provide me some help or understanding?
Thanks,