summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--json.sgml67
2 files changed, 75 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 2b5cc71..13aef92 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,3 @@
-subdir = contrib/json
-top_builddir = ../..
-include $(top_builddir)/src/Makefile.global
-
MODULE_big = json
OBJS = json.o json_io.o json_op.o
@@ -9,4 +5,13 @@ DATA_built = json.sql
DATA = uninstall_json.sql
REGRESS = json
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = contrib/json
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/json.sgml b/json.sgml
index d676a37..3180d3c 100644
--- a/json.sgml
+++ b/json.sgml
@@ -6,9 +6,74 @@
</indexterm>
<para>
- This module implements the <type>json</> data type for storing <ulink url="http://www.json.org/">JSON</ulink> content in <productname>PostgreSQL</>. It is currently under development.
+ This module implements the <type>json</> data type for storing <ulink url="http://www.json.org/">JSON</ulink> content in <productname>PostgreSQL</>. The advantage of using the <type>json</> type over storing JSON content in a <type>text</> field is that it makes sure input values are valid JSON, and there are several type-safe functions for manipulating JSON content.
</para>
+ <para>
+ The <type>json</> type stores valid JSON <quote>values</quote> as defined by <ulink url="http://json.org/">json.org</ulink>. That is, a <type>json</> field can hold a string, number, object, array, 'true', 'false', or 'null'.
+ </para>
+
+ <para>
+ The <type>json</> datatype should be thought of as a specialization of <type>text</type> rather than a wrapper around <type>text</>, <type>int</>, <type>float</>, etc. For instance, <literal>' "string" '::json::text</literal> will simply yield <literal>' "string" '</literal>. Also, bear in mind that JSON null (<literal>'null'::json</literal>) and SQL NULL (<literal>NULL::json</literal>) are two different things.
+ </para>
+
+ <para>
+ The json module is currently under development.
+ </para>
+
+ <sect2>
+ <title><type>json</> Functions</title>
+
+ <table id="json-func-table">
+ <title><type>json</> Functions</title>
+
+ <tgroup cols="5">
+ <thead>
+ <row>
+ <entry>Function</entry>
+ <entry>Return Type</entry>
+ <entry>Description</entry>
+ <entry>Example</entry>
+ <entry>Result</entry>
+ </row>
+ </thead>
+
+ <tbody>
+ <row>
+ <entry><function>from_json(json)</function></entry>
+ <entry><type>text</type></entry>
+ <entry>decode a JSON-encoded value</entry>
+ <entry><literal>from_json('"string"')</literal></entry>
+ <entry><literal>string</literal></entry>
+ </row>
+ <row>
+ <entry><function>to_json(anyelement)</function></entry>
+ <entry><type>json</type></entry>
+ <entry>encode a value as JSON</entry>
+ <entry><literal>to_json('string'::TEXT)</literal></entry>
+ <entry><literal>"string"</literal></entry>
+ </row>
+ <row>
+ <entry><function>json_type(json)</function></entry>
+ <entry><type>json_type_t</type> - one of:
+<programlisting>
+'null'
+'string'
+'number'
+'bool'
+'object'
+'array'
+</programlisting>
+ </entry>
+ <entry>Get the type of a <type>json</type> value.</entry>
+ <entry><literal>SELECT json_type('{"pi": "3.14159", "e": "2.71828"}');</literal></entry>
+ <entry><literal>object</literal></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </sect2>
+
<sect2>
<title>Author</title>