Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7917369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:07:22+00:00 2026-06-03T15:07:22+00:00

I am looking for some docs and/or examples for the new JSON functions in

  • 0

I am looking for some docs and/or examples for the new JSON functions in PostgreSQL 9.2.

Specifically, given a series of JSON records:

[
  {name: "Toby", occupation: "Software Engineer"},
  {name: "Zaphod", occupation: "Galactic President"}
]

How would I write the SQL to find a record by name?

In vanilla SQL:

SELECT * from json_data WHERE "name" = "Toby"

The official dev manual is quite sparse:

  • http://www.postgresql.org/docs/devel/static/datatype-json.html
  • http://www.postgresql.org/docs/devel/static/functions-json.html

Update I

I’ve put together a gist detailing what is currently possible with PostgreSQL 9.2.
Using some custom functions, it is possible to do things like:

SELECT id, json_string(data,'name') FROM things
WHERE json_string(data,'name') LIKE 'G%';

Update II

I’ve now moved my JSON functions into their own project:

PostSQL – a set of functions for transforming PostgreSQL and PL/v8 into a totally awesome JSON document store

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:07:23+00:00Added an answer on June 3, 2026 at 3:07 pm

    Postgres 9.2

    I quote Andrew Dunstan on the pgsql-hackers list:

    At some stage there will possibly be some json-processing (as opposed
    to json-producing) functions, but not in 9.2.

    Doesn’t prevent him from providing an example implementation in PLV8 that should solve your problem. (Link is dead now, see modern PLV8 instead.)

    Postgres 9.3

    Offers an arsenal of new functions and operators to add "json-processing".

    • The manual on new JSON functionality.
    • The Postgres Wiki on new features in pg 9.3.

    The answer to the original question in Postgres 9.3:

    For a given table:

    CREATE TABLE json_tbl (data json);
    

    Query:

    SELECT object
    FROM   json_tbl
         , json_array_elements(data) AS object
    WHERE  object->>'name' = 'Toby';
    

    Advanced example:

    • Query combinations with nested array of records in JSON datatype

    For bigger tables you may want to add an expression index to increase performance:

    • Index for finding an element in a JSON array

    Postgres 9.4

    Adds jsonb (b for "binary", values are stored as native Postgres types) and yet more functionality for both types. In addition to expression indexes mentioned above, jsonb also supports GIN, btree and hash indexes, GIN being the most potent of these.

    • The manual on json and jsonb data types and functions.
    • The Postgres Wiki on JSONB in pg 9.4

    The manual goes as far as suggesting:

    In general, most applications should prefer to store JSON data as
    jsonb
    , unless there are quite specialized needs, such as legacy
    assumptions about ordering of object keys.

    Bold emphasis mine.
    Also, performance benefits from general improvements to GIN indexes.

    Postgres 9.5

    Complete jsonb functions and operators. Add more functions to manipulate jsonb in place and for display.

    • Major good news in the release notes of Postgres 9.5.

    Functionality and performance has been improved with every major Postgres version since. It’s pretty complete by now (as of Postgres 16). One major, notable addition in …

    Postgres 12

    … is the SQL/JSON path language along with operators and functions. The answer to the example in the question can now be, for a given table (with jsonb):

    CREATE TABLE jsonb_tbl (data jsonb);
    
    SELECT jsonb_path_query_first(data, '$[*] ? (@.name == "Toby")') AS object
    FROM   jsonb_tbl
    WHERE  data @> '[{"name": "Toby"}]';  -- optional, for index support
    

    Or equivalent:

    ...
    WHERE  data @@ '$[*].name == "Toby"';
    

    fiddle

    See:

    • Returning JSON arrary with particular property using Postgres

    About indexing:

    • Find rows containing a key in a JSONB array of records
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for some good documentation for Mallet, specifically for its classes related to
I'm fiddling with a bit of c++/opencv. I was looking some of the samples
Looking for some advice on the best way to implement localization along with client
Looking for some guidance on a WCF service I’m prototyping. I have a WCF
Looking for some resources on SOA / BPEL best practices. Specially BPEL.
Looking for some help! I need to split a string at the last occurrence
looking for some help with images referenced within the stylesheet. I have no problems
Looking for some help with optimising the query below. Seems to be two bottlenecks
I looking for some information about the difference of the different session types available
While looking at some conceptual questions in C,I came across this question in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.