SQL/JSON is postponed

Back in March and April I wrote couple of blogposts about upcoming new great feature – full SQL/JSON.

Unfortunately, as of today SQL/JSON has been reverted (removed from sources), both from development version 16, but also from “almost ready" version 15.

There is lengthy discussion about it which you can definitely read if you're so inclined (side note, I didn't catch it immediately, so for future me – RMT is Release Management Team.

Obviously the feature will make its comeback. Whether it will be in 16 or later – can't tell now, but it will definitely reappear.

New SQL pretty printer – based on parsing, and not regexps

For a long time I was looking for SQL pretty printer.

Some queries that I had to deal with, over the years, were just insane to read, like this:

Continue reading New SQL pretty printer – based on parsing, and not regexps

Better scrolling of long explain plans on explain.depesz.com

Thanks to some discussion on Slack, and work by Alexandre Felipe viewing of large explains will be now a bit easier.

You can see it, for example, in this explain.

First of all, when you scroll down, the column headers stay in place. Plus – you can always see the horizontal scrollbar to see the rest for really long node descriptions.

Thanks a lot, I appreciate the work.

Waiting for PostgreSQL 15 – Documentation for SQL/JSON features

On 8th of April 2022, Andrew Dunstan committed patch:

Documentation for SQL/JSON features
 
This documents the features added in commits f79b803dcc, f4fb45d15c,
33a377608f, 1a36bc9dba, 606948b058, 49082c2cc3, 4e34747c88, and
fadb48b00e.
 
I have cleaned up the aggregate section of the submitted docs, but there
is still a deal of copy editing required. However, I thought it best to
have some documentation sooner rather than later so testers can have a
better idea what they are playing with.
 
Nikita Glukhov
 
Reviewers have included (in no particular order) Andres Freund, Alexander
Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers, Zhihong Yu,
Himanshu Upadhyaya, Daniel Gustafsson, Justin Pryzby.
 
Discussion: https://postgr.es/m/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru
Discussion: https://postgr.es/m/7e2cb85d-24cf-4abb-30a5-1a33715959bd@postgrespro.ru

Continue reading Waiting for PostgreSQL 15 – Documentation for SQL/JSON features

Waiting for PostgreSQL 15 – JSON_TABLE

On 4th of April 2022, Andrew Dunstan committed patch:

JSON_TABLE
 
This feature allows jsonb data to be treated as a table and thus used in
a FROM clause like other tabular data. Data can be selected from the
jsonb using jsonpath expressions, and hoisted out of nested structures
in the jsonb to form multiple rows, more or less like an outer join.
 
Nikita Glukhov
 
Reviewers have included (in no particular order) Andres Freund, Alexander
Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers, Zhihong Yu (whose
name I previously misspelled), Himanshu Upadhyaya, Daniel Gustafsson,
Justin Pryzby.
 
Discussion: https://postgr.es/m/7e2cb85d-24cf-4abb-30a5-1a33715959bd@postgrespro.ru

Continue reading Waiting for PostgreSQL 15 – JSON_TABLE

DBA tips ‘n tricks – search in every field in a table

Sometimes you just want to find some value, regardless of which column it's in. If the table has few columns you can easily:

=$ SELECT * FROM TABLE WHERE a ~ '...' OR b ~ '...' OR c ~ '...'

But if there are many columns writing such query quickly becomes tedious. Luckily there is simple solution.

Continue reading DBA tips ‘n tricks – search in every field in a table

Waiting for PostgreSQL 15 – SQL/JSON query functions

On 29th of March 2022, Andrew Dunstan committed patch:

SQL/JSON query functions
 
This introduces the SQL/JSON functions for querying JSON data using
jsonpath expressions. The functions are:
 
JSON_EXISTS()
JSON_QUERY()
JSON_VALUE()
 
All of these functions only operate on jsonb. The workaround for now is
to cast the argument to jsonb.
 
JSON_EXISTS() tests if the jsonpath expression applied to the jsonb
value yields any values. JSON_VALUE() must return a single value, and an
error occurs if it tries to return multiple values. JSON_QUERY() must
return a json object or array, and there are various WRAPPER options for
handling scalar or multi-value results. Both these functions have
options for handling EMPTY and ERROR conditions.
 
Nikita Glukhov
 
Reviewers have included (in no particular order) Andres Freund, Alexander
Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers, Zihong Yu,
Himanshu Upadhyaya, Daniel Gustafsson, Justin Pryzby.
 
Discussion: https://postgr.es/m/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru

Continue reading Waiting for PostgreSQL 15 – SQL/JSON query functions