Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONB Columns in the domain tables #21

Open
M-Hoogie opened this issue Aug 11, 2022 · 0 comments
Open

JSONB Columns in the domain tables #21

M-Hoogie opened this issue Aug 11, 2022 · 0 comments

Comments

@M-Hoogie
Copy link

M-Hoogie commented Aug 11, 2022

The current examples for JSONB (yum and apt) are outside the domain of the DVD rental example. It might be more beneficial to add JSONB columns to either the existing view or to create a new (materialized) view that has these json columns. An example below.

-- actor_info view
SELECT a.actor_id,
       a.first_name,
       a.last_name,
       jsonb_object_agg(c.name, (SELECT array_agg(f.title) AS array_agg
                                             FROM film f
                                                      JOIN film_category fc_1 ON f.film_id = fc_1.film_id
                                                      JOIN film_actor fa_1 ON f.film_id = fa_1.film_id
                                             WHERE fc_1.category_id = c.category_id
                                               AND fa_1.actor_id = a.actor_id
                                             GROUP BY fa_1.actor_id)) AS film_info
FROM actor a
         LEFT JOIN film_actor fa ON a.actor_id = fa.actor_id
         LEFT JOIN film_category fc ON fa.film_id = fc.film_id
         LEFT JOIN category c ON fc.category_id = c.category_id
GROUP BY a.actor_id, a.first_name, a.last_name;

This would enable users to get more familiar with different jsonb operator when filtering on the view. For instance this simple example below

SELECT actor_id, first_name, last_name, film_info
FROM actor_info
WHERE film_info -> 'Games' ? 'FEATHERS METAL'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant