JSON will be a core type in PostgreSQL 9.2
people.planetpostgresql.org
people.planetpostgresql.org
The Heroku Postgres guys have been playing with this idea [2] using the PL/V8 plugin, which embeds Javascript as a supported language inside Postgres (and thus makes it trivial to implement the json_project_key function), but if Postgres is going to natively support JSON parsing then it shouldn't take an addon module to achieve this.
[1] Attempting to forestall the thread-jacking: I know NoSQL databases have other benefits besides their data model, but for some applications that's certainly one of the benefits. [2] https://gist.github.com/1150804
Reading from the linked article I would assume that they were kind of running out of time for the feature freeze.
I would expect the querying functions to be added in the release after this, or before in form of an extension.
I'm not on their core developer mailing lists, but I presume this is because of a prioritization of stability over most everything else.
They'll take a stable half-feature over a buggy full-feature at any given deadline. What matters is that over time they patiently and carefully expand those half features.
The most visible example is the slowly increasing coverage of replication. This JSON feature is another example -- I expect it will grow in future into a fuller feature set.
They already have that: http://www.postgresql.org/docs/9.1/static/hstore.html
That said, having seen 'core type' I instantly imagined being able to query based on JSON properties, which doesn't appear to be the case. Not surprising, because it would be a huge amount of work.. but it's nice to imagine.
(before anyone says anything- yes, I know NoSQL exists. But a hybrid solution using Postgres would be very interesting)
It's a key-value store that allows querying, which is what I think you are lamenting in your comment. Here's a bit more about how to query and index with hstore: http://lwn.net/Articles/406385/. It's pretty simple and doesn't have anywhere near the number of querying possibilities that MongoDB has, but it can be used for on-the-fly column names (similar to JSON). You can only query on the root node's children, unlike the open-ended possibilities in NoSQL.
I'm (quite happily) tied to Postgres because I'm using PostGIS, but the ability to add freeform data to a location would be ideal. Looks like I may already have a solution here.
It's not without a learning curve, but I found it helpful when I hit shortcomings in Mongo's design.
That part doesn't require PostGIS as such, but it's for an NYC city government app competition, so we have all sort of city datasets to use. I've used PostGIS to help make custom map tiles (preview at https://twitter.com/#!/taxonomyapp/status/149565007384940545), highlight the outline of the building you're heading to... all sorts. It's been a fantastic learning exercise.
http://www.mongodb.org/display/DOCS/Geospatial+Indexing http://www.mongodb.org/display/DOCS/Geospatial+Haystack+Inde...
Don't combine your data structures / stores. Use the store / structure that is most appropriate for the given task. Memory is cheap vs compute time.
Hint: many can be only in memory stores that periodically sync to a backing store for updates.
SELECT users.id, jsonpath('$.timezone', users.preferences_json) AS tz FROM users WHERE tz LIKE 'America/%';In general, a few core limitations of the current optimizer - lack of LATERAL key among them - make it impossible to create a PostgreSQL function that blends well with SQL, AFAICT.
PostgreSQL does support functional indexes, so you can easily make this use indexes and thus be fast enough for real use (it's a bad example - I'd probably put the address into an addresses table, but it's enough to illustrate the point)
http://people.planetpostgresql.org/andrew/index.php?/archive...
If JSON support means first-class type support in a nested object, that's a huge leap forward.
SELECT xml_user_roster( 1 );
Given the extensive use of JSON in jQuery (Ajax) web applications, integrating JSON with PostgreSQL is smart. It allows the application code to vary independently of the business code that relies on JSON as a data interchange format.That said, it would be great if JSON and XML were pluggable modules (similar to PL/R) that could be installed when needed.
SELECT
xmlroot(
xmlelement( name root,
xmlelement( name description,
xmlelement( name title, table.title ),
xmlelement( name diet, table.diet ) ), etc.
If the format of the XML was out of the developer's control, XSL is a relatively easy way to convert XML from one format to another. If XSL won't handle it, then any number of ETL tools would be more than sufficient. Unless you mean something else by "flavour of XML"?To get the same document using a language external to the database requires the following steps:
1. Write the SQL statement (a stored procedure, view, or string).
2. Instantiate an XML document library (e.g., PHP's DOM).
3. Iterate over the result set(s).
4. Build the XML document from the results.
Note that the first step is always required in both situations (whether the query is internal or external to the database).Steps 2 to 4 effectively echo the first step: they tightly couple the XML format to the expected result set(s) from the database query. There is no abstraction to the application, there is no visible gain.
Also, with XML you can add meta information to the element: <date format="dd-MMM-yyyy">02-FEB-2012</date>. In PostgreSQL, you would use the xmlattribute function.
So, if you already have an environment where you are certain you are inserting valid JSON, it's not much different than just using the text type today.
Today, yes.
Tomorrow, when you launch an API and suddenly hundreds of different apps are talking to your systems, no.
Putting rich descriptions of data right next to the data is a good thing in the long run.
I suspect I am not a big fan of abstractions.
The new constraint allowing you to ensure the string stored is valid JSON sounds useful though.
There are good reasons to have JSON support in the DBMS, such as querying and indexing on the fields within a JSON document.
My only criticism is that postgres has a great extensions mechanism, and it would be better if effort were spent improving the ecosystem around that. I can't think of any reason for it to be in core if installing an extension were a trivial and widely accepted practice.
But, it takes time to really develop that ecosystem. And there are users that want JSON support yesterday.
EDIT: from a technological standpoint, there is no reason why it can't exist as an extension. PostGIS is much more sophisticated on all counts, and it's an extension.
Right now the perception of Postgres...actually, databases in general,
including virtually all of the newcomers -- is that they are
monolithic systems, and for most people either "9.3" will "have"
javascript and indexing of JSON documents, or it won't. In most cases
I would say "meh, let them eat cake until extensions become so
apparently dominant that we can wave someone aside to extension-land",
but in this case I think that would be a strategic mistake.
http://archives.postgresql.org/pgsql-hackers/2011-12/msg0078...So this is definitely a social problem. Why not move UUID out of the core? (not uuid-ossp, which implements generation, but uuid parsing and storage) Because, for now, one cannot assume extensions for really common useful functionality.
Luckily, I think things are on the right path to at a future juncture that even a commonly desired data type can live as an extension.
SQLight. Nice pick.