Commits

Andrew Dunstan  committed 1eb26c2

rename hstore_to_json functions, use strict version for cast.

  • Participants
  • Parent commits d308c18
  • Branches jsonng

Comments (0)

Files changed (2)

File contrib/hstore/hstore--1.1.sql

 CREATE CAST (hstore AS json)
   WITH FUNCTION hstore_to_json(hstore);
 
-CREATE FUNCTION hstore_to_json_strict(hstore)
+CREATE FUNCTION hstore_to_json_loose(hstore)
 RETURNS json
-AS 'MODULE_PATHNAME', 'hstore_to_json_strict'
+AS 'MODULE_PATHNAME', 'hstore_to_json_loose'
 LANGUAGE C IMMUTABLE STRICT;
 
 CREATE FUNCTION hstore(record)

File contrib/hstore/hstore_io.c

 	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
 
-PG_FUNCTION_INFO_V1(hstore_to_json);
-Datum		hstore_to_json(PG_FUNCTION_ARGS);
+
+/*
+ * hstore_to_json_loose
+ *
+ * This is a heuristic conversion to json which treats
+ * 't' and 'f' as booleans and strings that look like numbers as numbers,
+ * as long as they don't start with a leading zero followed by another digit
+ * (think zip codes or phone numbers starting with 0).
+ */
+PG_FUNCTION_INFO_V1(hstore_to_json_loose);
+Datum		hstore_to_json_loose(PG_FUNCTION_ARGS);
 Datum
-hstore_to_json(PG_FUNCTION_ARGS)
+hstore_to_json_loose(PG_FUNCTION_ARGS)
 {
 	HStore	   *in = PG_GETARG_HS(0);
 	int			buflen,
 	PG_RETURN_TEXT_P(cstring_to_text(out));
 }
 
-PG_FUNCTION_INFO_V1(hstore_to_json_strict);
-Datum		hstore_to_json_strict(PG_FUNCTION_ARGS);
+PG_FUNCTION_INFO_V1(hstore_to_json);
+Datum		hstore_to_json(PG_FUNCTION_ARGS);
 Datum
-hstore_to_json_strict(PG_FUNCTION_ARGS)
+hstore_to_json(PG_FUNCTION_ARGS)
 {
 	HStore	   *in = PG_GETARG_HS(0);
 	int			buflen,