Skip to content
Advertisement

PostgreSQL Generated Column from a JSONB column with nested values

I have following table with a JSONB column:

The data in the column looks like this:

Now I want to add a generated column of vectors. It should only contain last_name of the JSONB column:

Can anyone help me out how to do that? Vectors should look like this 'freeman':2 'robbin':1 Demo on DB Fiddle

Advertisement

Answer

With the JSON Path expression you can specify the items in the JSON data. With following example only items with the key last_name will be included:

Demo on DB Fiddle

Thank you RhodiumToad in the #postgresql IRC channel for providing a solution for this problem ????‍♂️

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