deparse: Fix and actually use support for ObjTypeInteger in SET STATISTICS.
authorAndres Freund <andres@anarazel.de>
Wed, 26 Nov 2014 01:32:05 +0000 (02:32 +0100)
committerAndres Freund <andres@anarazel.de>
Wed, 26 Nov 2014 01:32:05 +0000 (02:32 +0100)
src/backend/commands/event_trigger.c
src/backend/tcop/deparse_utility.c

index 4df85447d027db1130da1a437f65e760fca5fc81..0fd09233a5b08d327a6d0b0b1dff5297f7678768 100644 (file)
@@ -1735,7 +1735,8 @@ typedef enum
 {
    JsonTypeArray,
    JsonTypeObject,
-   JsonTypeString
+   JsonTypeString,
+   JsonTypeNumber
 } JsonType;
 
 typedef enum
@@ -1744,6 +1745,7 @@ typedef enum
    SpecOperatorname,
    SpecDottedName,
    SpecString,
+   SpecNumber,
    SpecStringLiteral,
    SpecIdentifier
 } convSpecifier;
@@ -1840,6 +1842,8 @@ jsonval_get_type(Datum jsonval, char **typename)
        json_elt_type = JsonTypeObject;
    else if (strcmp(paramtype, "string") == 0)
        json_elt_type = JsonTypeString;
+   else if (strcmp(paramtype, "number") == 0)
+       json_elt_type = JsonTypeNumber;
    else
        /* XXX improve this; need to specify array index or param name */
        elog(ERROR, "unexpected JSON element type %s",
@@ -2096,6 +2100,12 @@ expand_jsonval_string(StringInfo buf, Datum jsonval, JsonType json_elt_type)
    }
 }
 
+static void
+expand_jsonval_number(StringInfo buf, Datum jsonval)
+{
+   appendStringInfoString(buf, TextDatumGetCString(jsonval));
+}
+
 /*
  * Expand a json value as a string literal
  */
@@ -2180,6 +2190,11 @@ expand_one_element(StringInfo buf, char *param,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                 errmsg("expected JSON string or object for %%s element \"%s\", got %s",
                        param, valtype)));
+   if (specifier == SpecNumber && json_elt_type != JsonTypeNumber)
+       ereport(ERROR,
+               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                errmsg("expected JSON string or object for %%d element \"%s\", got %s",
+                       param, valtype)));
 
    switch (specifier)
    {
@@ -2199,6 +2214,10 @@ expand_one_element(StringInfo buf, char *param,
            expand_jsonval_strlit(buf, jsonval);
            break;
 
+       case SpecNumber:
+           expand_jsonval_number(buf, jsonval);
+           break;
+
        case SpecTypename:
            expand_jsonval_typename(buf, jsonval);
            break;
@@ -2253,6 +2272,7 @@ expand_one_array_element(StringInfo buf, Datum array, int idx, char *param,
  * O       expand as an operator name
  * L       expand as a string literal (quote using single quotes)
  * s       expand as a simple string (no quoting)
+ * d       expand as a simple number (no quoting)
  *
  * The element name may have an optional separator specification preceded
  * by a colon. Its presence indicates that the element is expected to be
@@ -2368,6 +2388,7 @@ pg_event_trigger_expand_command(PG_FUNCTION_ARGS)
         * 'O' -- expand as an operator name. Same as 'D', but the objname
         *        element is not quoted.
         * 's' -- expand as a simple string; no quoting.
+        * 'd' -- expand as a number.
         * 'T' -- expand as a typename, with ad-hoc rules
         */
        switch (*cp)
@@ -2381,6 +2402,9 @@ pg_event_trigger_expand_command(PG_FUNCTION_ARGS)
            case 's':
                specifier = SpecString;
                break;
+           case 'd':
+               specifier = SpecNumber;
+               break;
            case 'L':
                specifier = SpecStringLiteral;
                break;
index 33590116709c75a17220c600403dad6497ae19f1..aa9f0291bd0d4d8a12499d42e93f6a0532246dac 100644 (file)
@@ -416,7 +416,7 @@ jsonize_objtree(ObjTree *tree)
                typeid = BOOLOID;
                break;
            case ObjTypeInteger:
-               typeid = INT4OID;
+               typeid = INT8OID;
                break;
            case ObjTypeArray:
            case ObjTypeObject:
@@ -442,7 +442,7 @@ jsonize_objtree(ObjTree *tree)
                values[i - 1] = CStringGetTextDatum(object->str_value);
                break;
            case ObjTypeInteger:
-               values[i - 1] = Int32GetDatum(object->int_value);
+               values[i - 1] = Int64GetDatum(object->int_value);
                break;
            case ObjTypeArray:
                {
@@ -4422,7 +4422,7 @@ deparse_AlterTableStmt(StashedCommand *cmd)
            case AT_SetStatistics:
                {
                    Assert(IsA(subcmd->def, Integer));
-                   tmp = new_objtree_VA("ALTER COLUMN %{column}I SET STATISTICS %{statistics}s",
+                   tmp = new_objtree_VA("ALTER COLUMN %{column}I SET STATISTICS %{statistics}d",
                                         3, "type", ObjTypeString, "set statistics",
                                         "column", ObjTypeString, subcmd->name,
                                         "statistics", ObjTypeInteger, intVal((Value *) subcmd->def));