0

I am creating some views by working with those data bassically UUID and some concepts, I managed to obtain what I expected from the first level, but I am having problems when trying to obtain second level data. The table I am working within the column tiledata are some nested data which I would like to access, this is the

table I am working on

When I run the query

SELECT tileid, nodegroupid,
   tiledata ->'34cfea8a-c2c0-11ea-9026-02e7594ce0a0' AS ACTOR
   FROM tiles
   WHERE tiledata -> '34cfea8a-c2c0-11ea-9026-02e7594ce0a0' IS NOT NULL;

I obtain this

after query

How Could I obtain for example resourceId from this nested data,

obtaining all the rows which have resourceId

1
  • 2
    Sample data is better presented as formatted text which can be copied to build up a test-bed. See here for some tips on how to create nice looking tables. Commented Aug 21, 2020 at 12:03

1 Answer 1

2

You can use the jsonb_array_elements function to extract each element of a JSONB array as a new JSONB value on which you can use any other JSONB function or operator.

The thing to know is that each array value will generate a new row in the record set.


In your case, you can try:

SELECT tileid, nodegroupid,
   jsonb_array_elements(tiledata ->'34cfea8a-c2c0-11ea-9026-02e7594ce0a0')->'resourceID'
   FROM tiles
   WHERE tiledata -> '34cfea8a-c2c0-11ea-9026-02e7594ce0a0' IS NOT NULL;

See this fiddle for a simple example.

See the doc for more details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.