Skip to content
Advertisement

Rails & Postgres selecting sub keys of a JSONB column

I have a column of a database table that is of type JSONB and I’m wanting to get some data from that column. For the most part the column is a flat list of key value pairs.

Ex:

However, the key I’m after contains an array of JSON data (or can be null/nil):

Now, what I want I do is have a sub select that gives me the concat’d name string (first_name + last_name) based on the ind (whether or not it’s true/’true’). So, I want an output of:

I’ve achieved this — to a degree — with this PSQL Snippet:

Is there a way to simplify the SQL statement (& how do I add the bit for the ind = [true, 'true']?

Advertisement

Answer

I achieved what I wanted with the above. Thought I’d throw it on here.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement