Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

JSON By The Other Elephant

1,004 views

Published on

PostgreSQL JSON features. The Talk was done at the Berlin PHP Usergroup (http://www.bephpug.de/) on 7th of July 2015.

The script used during the talk is available at my GitHub account https://github.com/sjstoelting/talks/tree/master/json-by-the-other-elephant

Published in: Software
  • Be the first to like this

JSON By The Other Elephant

  1. 1. JSON by the other elephant PHP Usergroup Berlin July 2015 Stefanie Janine Stölting
  2. 2. JSON ● JavaScript Object Notation ● Don't have to care about encoding, it is always UTF8 ● Used for data exchange in web application ● Currently two standards RFC 7159 by Douglas Crockford und ECMA-404 ● PostgreSQL impementation is RFC 7159
  3. 3. CTE Common Table Expressions will be used in examples ● Example: WITH RECURSIVE t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 100 ) SELECT sum(n), min(n), max(n) FROM t; ● Result:
  4. 4. JSON Datatypes ● JSON – Available since 9.2 ● JSONB – Available since 9.4 – Crompessed JSON
  5. 5. JSON Functions ● row_to_json({row}) Returns the row as JSON ● array_to_json({array}) Returns the array as JSON ●
  6. 6. JSON Opertators ● Array Element ->{int} ● Object Element ->> {text}
  7. 7. Index on JSON ● Index JSONB content for faster access with indexes – GIN index overall ● CREATE INDEX idx_1 ON jsonb.actor USING GIN (jsondata); – Even unique B-Tree indexes are possible ● CREATE UNIQUE INDEX actor_id_2 ON jsonb.actor((CAST(jsondata->>'actor_id' AS INTEGER)));
  8. 8. New JSON functions ● With the next version, 9.5, there will be new functions available. – jsonb_pretty – jsonb_set ● If you can't wait using them, you might be interested in the jsonbx extentsion available at PGXN
  9. 9. User Group / Conferences PostgreSQL User Group Berlin PostgreSQL Europe Conference 2015 Vienna, October 27-30 German PostgreSQL Conference 2015 Hamburg, November 26-27
  10. 10. Link List Extended JSONB functions for 9.5 Extended JSONB functions as extension for 9.4 as extension from PGXN (jsonbx) Sakila database from MySQL pgloader to convert the Sakila database into PostgreSQL
  11. 11. JSON by the other Elephant This is licencensed by Stefanie Janine Stölting as Attribution 4.0 International (CC BY 4.0). Find me on Twitter as @sjstoelting

×