STUART Hayes
STUART Hayes

Reputation: 1

Postgres return JSON element

I have a JSON field ('ez_links') in a table ('bookings') and I wish to return a particular attribute/element ('Amount'), which represents the price of the booking.

In the example below, I want to return the value of '662', but NULL is returned.

select ez_links, ez_links-> 'Amount' AS price
FROM bookings
limit 1

Result:

ez_links price
{"integrator": "ezlinks", "TeeTimeReserveRecord": {"Fee": "Troon App Member", "Amount": "662",...........................................}} NULL

Thanks for your help.

Upvotes: 0

Views: 25

Answers (1)

kartikey rajvaidya
kartikey rajvaidya

Reputation: 91

This is a nested JSON, you can do the following to access the Amount field

SELECT ez_links->'TeeTimeReserveRecord'->'Amount' as price FROM bookings
limit 1                                                                                                                  ;

I hope this was helpful.

Upvotes: 2

Related Questions