{
  "$schema": "/products/haybarn/functions/api/v1/function.schema.json",
  "schemaVersion": 1,
  "name": "sum",
  "schema": "main",
  "slug": "sum",
  "description": "Calculates the sum value for all tuples in arg.",
  "category": "aggregate",
  "kinds": [
    "aggregate"
  ],
  "aliasOf": [],
  "snapshot": {
    "schemaVersion": 1,
    "id": "duckdb-2.0.0",
    "engine": "duckdb",
    "label": "DuckDB 2.0.0",
    "engineVersion": "v2.0.0",
    "sourceId": "d54cbbe3df",
    "source": "https://github.com/duckdb/duckdb/releases/tag/v2.0.0",
    "binarySha256": "4d5d001f4b0a16c16f1bc83338153a70bec7e58f0cae0eec4b44b9b9afa0bef0",
    "capturedAt": "2026-11-06T18:35:28.343Z",
    "requestedExtensions": [
      "core_functions",
      "icu",
      "json",
      "parquet"
    ],
    "loadedExtensions": [
      {
        "extension_name": "autocomplete",
        "extension_version": "v2.0.0",
        "installed_from": ""
      },
      {
        "extension_name": "core_functions",
        "extension_version": "v2.0.0",
        "installed_from": ""
      },
      {
        "extension_name": "icu",
        "extension_version": "v2.0.0",
        "installed_from": ""
      },
      {
        "extension_name": "json",
        "extension_version": "v2.0.0",
        "installed_from": ""
      },
      {
        "extension_name": "parquet",
        "extension_version": "v2.0.0",
        "installed_from": ""
      },
      {
        "extension_name": "shell",
        "extension_version": "v2.0.0",
        "installed_from": ""
      }
    ],
    "scope": "Built-in functions in the main schema, with the requested extensions loaded. Catalog visibility is not a guarantee of browser support."
  },
  "links": {
    "html": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/",
    "markdown": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/index.md",
    "json": "/products/haybarn/functions/api/v1/duckdb-2.0.0/functions/sum.json"
  },
  "interpretation": [
    "Choose a snapshot matching the target engine and build. The default is captured from the published Haybarn WASM package used by the browser playground. Historical native snapshots are also available.",
    "Availability is an observation in the recorded build and extension profile, not a guarantee of support in every installation or in WASM.",
    "Types and descriptions are declarations from duckdb_functions(). Binding can specialize result types. Null means not supplied by the catalog; do not invent defaults, optionality, argument mode, or table output columns.",
    "Raw parameter arrays preserve catalog order for scalar/aggregate/macro functions. Raw table arguments are alphabetical. Use callingConvention for engine-confirmed positional order and named arguments; null modes are unrecorded. Named does not mean optional. Macro defaults and special named variadic behavior are not supplied by duckdb_functions().",
    "Catalog examples are source material and may require data or extensions. runnableExamples contains separately verified SQL for the pinned WASM package; sample-data adaptations and guide examples are labeled separately.",
    "Guide annotations and recipes are separate editorial content. The browser runner always uses Haybarn WASM 2.0.0-rc12, independently of the documentation snapshot.",
    "All URLs beginning with / are relative to the origin hosting this document. Exports require no JavaScript, cookies, API key, or browser engine."
  ],
  "overloads": [
    {
      "id": "overload-364e1499a3b31b6d",
      "url": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/#overload-364e1499a3b31b6d",
      "signature": "sum(arg: BIGINT) → HUGEINT",
      "parameterOrder": "catalog-order",
      "callingConvention": {
        "source": null,
        "parameters": [
          {
            "name": "arg",
            "type": "BIGINT",
            "mode": null,
            "position": null
          }
        ],
        "positional": null,
        "named": null,
        "variadic": null,
        "evidence": null
      },
      "syntax": {
        "kind": "function",
        "operator": null
      },
      "catalog": {
        "schema_name": "main",
        "function_name": "sum",
        "function_type": "aggregate",
        "description": "Calculates the sum value for all tuples in arg.",
        "comment": null,
        "return_type": "HUGEINT",
        "parameters": [
          "arg"
        ],
        "parameter_types": [
          "BIGINT"
        ],
        "varargs": null,
        "macro_definition": null,
        "has_side_effects": false,
        "internal": true,
        "examples": [
          "sum(A)"
        ],
        "stability": "CONSISTENT",
        "categories": [],
        "alias_of": null
      }
    },
    {
      "id": "overload-5d3b17dd154d827e",
      "url": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/#overload-5d3b17dd154d827e",
      "signature": "sum(arg: BIGNUM) → BIGNUM",
      "parameterOrder": "catalog-order",
      "callingConvention": {
        "source": null,
        "parameters": [
          {
            "name": "arg",
            "type": "BIGNUM",
            "mode": null,
            "position": null
          }
        ],
        "positional": null,
        "named": null,
        "variadic": null,
        "evidence": null
      },
      "syntax": {
        "kind": "function",
        "operator": null
      },
      "catalog": {
        "schema_name": "main",
        "function_name": "sum",
        "function_type": "aggregate",
        "description": "Calculates the sum value for all tuples in arg.",
        "comment": null,
        "return_type": "BIGNUM",
        "parameters": [
          "arg"
        ],
        "parameter_types": [
          "BIGNUM"
        ],
        "varargs": null,
        "macro_definition": null,
        "has_side_effects": false,
        "internal": true,
        "examples": [
          "sum(A)"
        ],
        "stability": "CONSISTENT",
        "categories": [],
        "alias_of": null
      }
    },
    {
      "id": "overload-f631ee5353c08dd7",
      "url": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/#overload-f631ee5353c08dd7",
      "signature": "sum(arg: BOOLEAN) → HUGEINT",
      "parameterOrder": "catalog-order",
      "callingConvention": {
        "source": null,
        "parameters": [
          {
            "name": "arg",
            "type": "BOOLEAN",
            "mode": null,
            "position": null
          }
        ],
        "positional": null,
        "named": null,
        "variadic": null,
        "evidence": null
      },
      "syntax": {
        "kind": "function",
        "operator": null
      },
      "catalog": {
        "schema_name": "main",
        "function_name": "sum",
        "function_type": "aggregate",
        "description": "Calculates the sum value for all tuples in arg.",
        "comment": null,
        "return_type": "HUGEINT",
        "parameters": [
          "arg"
        ],
        "parameter_types": [
          "BOOLEAN"
        ],
        "varargs": null,
        "macro_definition": null,
        "has_side_effects": false,
        "internal": true,
        "examples": [
          "sum(A)"
        ],
        "stability": "CONSISTENT",
        "categories": [],
        "alias_of": null
      }
    },
    {
      "id": "overload-707c3ce29eb71f2a",
      "url": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/#overload-707c3ce29eb71f2a",
      "signature": "sum(arg: DECIMAL) → DECIMAL",
      "parameterOrder": "catalog-order",
      "callingConvention": {
        "source": null,
        "parameters": [
          {
            "name": "arg",
            "type": "DECIMAL",
            "mode": null,
            "position": null
          }
        ],
        "positional": null,
        "named": null,
        "variadic": null,
        "evidence": null
      },
      "syntax": {
        "kind": "function",
        "operator": null
      },
      "catalog": {
        "schema_name": "main",
        "function_name": "sum",
        "function_type": "aggregate",
        "description": "Calculates the sum value for all tuples in arg.",
        "comment": null,
        "return_type": "DECIMAL",
        "parameters": [
          "arg"
        ],
        "parameter_types": [
          "DECIMAL"
        ],
        "varargs": null,
        "macro_definition": null,
        "has_side_effects": false,
        "internal": true,
        "examples": [
          "sum(A)"
        ],
        "stability": "CONSISTENT",
        "categories": [],
        "alias_of": null
      }
    },
    {
      "id": "overload-e815fe648ba59f1f",
      "url": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/#overload-e815fe648ba59f1f",
      "signature": "sum(arg: DOUBLE) → DOUBLE",
      "parameterOrder": "catalog-order",
      "callingConvention": {
        "source": null,
        "parameters": [
          {
            "name": "arg",
            "type": "DOUBLE",
            "mode": null,
            "position": null
          }
        ],
        "positional": null,
        "named": null,
        "variadic": null,
        "evidence": null
      },
      "syntax": {
        "kind": "function",
        "operator": null
      },
      "catalog": {
        "schema_name": "main",
        "function_name": "sum",
        "function_type": "aggregate",
        "description": "Calculates the sum value for all tuples in arg.",
        "comment": null,
        "return_type": "DOUBLE",
        "parameters": [
          "arg"
        ],
        "parameter_types": [
          "DOUBLE"
        ],
        "varargs": null,
        "macro_definition": null,
        "has_side_effects": false,
        "internal": true,
        "examples": [
          "sum(A)"
        ],
        "stability": "CONSISTENT",
        "categories": [],
        "alias_of": null
      }
    },
    {
      "id": "overload-696623bb8b4b05c9",
      "url": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/#overload-696623bb8b4b05c9",
      "signature": "sum(arg: HUGEINT) → HUGEINT",
      "parameterOrder": "catalog-order",
      "callingConvention": {
        "source": null,
        "parameters": [
          {
            "name": "arg",
            "type": "HUGEINT",
            "mode": null,
            "position": null
          }
        ],
        "positional": null,
        "named": null,
        "variadic": null,
        "evidence": null
      },
      "syntax": {
        "kind": "function",
        "operator": null
      },
      "catalog": {
        "schema_name": "main",
        "function_name": "sum",
        "function_type": "aggregate",
        "description": "Calculates the sum value for all tuples in arg.",
        "comment": null,
        "return_type": "HUGEINT",
        "parameters": [
          "arg"
        ],
        "parameter_types": [
          "HUGEINT"
        ],
        "varargs": null,
        "macro_definition": null,
        "has_side_effects": false,
        "internal": true,
        "examples": [
          "sum(A)"
        ],
        "stability": "CONSISTENT",
        "categories": [],
        "alias_of": null
      }
    },
    {
      "id": "overload-b0cae1c0988f2b33",
      "url": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/#overload-b0cae1c0988f2b33",
      "signature": "sum(arg: INTEGER) → HUGEINT",
      "parameterOrder": "catalog-order",
      "callingConvention": {
        "source": null,
        "parameters": [
          {
            "name": "arg",
            "type": "INTEGER",
            "mode": null,
            "position": null
          }
        ],
        "positional": null,
        "named": null,
        "variadic": null,
        "evidence": null
      },
      "syntax": {
        "kind": "function",
        "operator": null
      },
      "catalog": {
        "schema_name": "main",
        "function_name": "sum",
        "function_type": "aggregate",
        "description": "Calculates the sum value for all tuples in arg.",
        "comment": null,
        "return_type": "HUGEINT",
        "parameters": [
          "arg"
        ],
        "parameter_types": [
          "INTEGER"
        ],
        "varargs": null,
        "macro_definition": null,
        "has_side_effects": false,
        "internal": true,
        "examples": [
          "sum(A)"
        ],
        "stability": "CONSISTENT",
        "categories": [],
        "alias_of": null
      }
    },
    {
      "id": "overload-d79f5dbb9d7776cf",
      "url": "/products/haybarn/functions/releases/duckdb-2.0.0/sum/#overload-d79f5dbb9d7776cf",
      "signature": "sum(arg: SMALLINT) → HUGEINT",
      "parameterOrder": "catalog-order",
      "callingConvention": {
        "source": null,
        "parameters": [
          {
            "name": "arg",
            "type": "SMALLINT",
            "mode": null,
            "position": null
          }
        ],
        "positional": null,
        "named": null,
        "variadic": null,
        "evidence": null
      },
      "syntax": {
        "kind": "function",
        "operator": null
      },
      "catalog": {
        "schema_name": "main",
        "function_name": "sum",
        "function_type": "aggregate",
        "description": "Calculates the sum value for all tuples in arg.",
        "comment": null,
        "return_type": "HUGEINT",
        "parameters": [
          "arg"
        ],
        "parameter_types": [
          "SMALLINT"
        ],
        "varargs": null,
        "macro_definition": null,
        "has_side_effects": false,
        "internal": true,
        "examples": [
          "sum(A)"
        ],
        "stability": "CONSISTENT",
        "categories": [],
        "alias_of": null
      }
    }
  ],
  "editorial": {
    "argumentNotes": [],
    "usage": null,
    "recipes": [
      {
        "id": "bucket-dates",
        "title": "Give your timestamps a rhythm.",
        "description": "Group events into calendar months with date_trunc. The same pattern works for days, weeks, and years.",
        "sql": "SELECT\n  date_trunc('month', sold_at) AS month,\n  sum(amount) AS revenue\nFROM (VALUES\n  (DATE '2026-06-03', 120),\n  (DATE '2026-06-18', 85),\n  (DATE '2026-07-02', 150)\n) AS sales(sold_at, amount)\nGROUP BY 1 ORDER BY 1;",
        "source": "guide-recipe",
        "verification": null,
        "intendedRuntime": {
          "engine": "haybarn-wasm",
          "packageVersion": "2.0.0-rc12"
        }
      }
    ]
  },
  "examples": [
    {
      "original": "sum(A)",
      "sql": "SELECT sum(A);",
      "overloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "source": "engine-catalog",
      "verification": null
    }
  ],
  "translations": [
    {
      "function": "sum",
      "scope": "",
      "relation": "direct",
      "source": {
        "engine": "BigQuery",
        "dialect": "bigquery",
        "name": "sum",
        "names": [
          "sum"
        ],
        "sql": "SELECT SUM(x IGNORE NULLS) AS x"
      },
      "target": {
        "dialect": "duckdb",
        "name": "sum",
        "sql": "SELECT SUM(x) AS x"
      },
      "formatTokens": [],
      "executionVerified": false,
      "provenance": {
        "name": "SQLGlot",
        "commit": "3086608e6fd4c41c02dfba47171608d2b193fce2",
        "url": "https://github.com/tobymao/sqlglot/blob/3086608e6fd4c41c02dfba47171608d2b193fce2/tests/dialects/test_bigquery.py#L723"
      }
    },
    {
      "function": "sum",
      "scope": "",
      "relation": "rewrite",
      "source": {
        "engine": "Snowflake",
        "dialect": "snowflake",
        "name": "",
        "names": [
          "pivot",
          "sum"
        ],
        "sql": "SELECT * FROM produce PIVOT(SUM(produce.sales) FOR produce.quarter IN ('Q1', 'Q2'))"
      },
      "target": {
        "dialect": "duckdb",
        "name": "sum",
        "sql": "SELECT * FROM produce PIVOT(SUM(sales) FOR quarter IN ('Q1' AS \"'Q1'\", 'Q2' AS \"'Q2'\"))"
      },
      "formatTokens": [],
      "executionVerified": false,
      "provenance": {
        "name": "SQLGlot",
        "commit": "3086608e6fd4c41c02dfba47171608d2b193fce2",
        "url": "https://github.com/tobymao/sqlglot/blob/3086608e6fd4c41c02dfba47171608d2b193fce2/tests/dialects/test_duckdb.py#L908"
      }
    }
  ],
  "runnableExamples": [
    {
      "function": "sum",
      "original": "sum(A)",
      "sql": "SELECT sum(A)\nFROM (VALUES\n  (10),\n  (20),\n  (NULL)\n) AS sample(\"A\");",
      "source": "catalog-with-sample-data",
      "verification": {
        "engine": "haybarn-wasm",
        "packageVersion": "2.0.0-rc12",
        "sourceId": "9b1a0c5829",
        "binarySha256": "07ab540b40e7dded86546a179f58276085900a44e92d1aa070072360c1f78ae6",
        "rowCount": 1
      }
    }
  ],
  "additionalDocumentation": [
    {
      "title": "Aggregate Functions",
      "url": "https://duckdb.org/docs/current/sql/functions/aggregates#sumarg"
    },
    {
      "title": "Window Functions",
      "url": "https://duckdb.org/docs/current/sql/functions/window_functions#examples"
    }
  ],
  "availability": [
    {
      "snapshot": "haybarn-2.0.0-rc12",
      "observed": true,
      "overloadCount": 8,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/haybarn-2.0.0-rc12/functions/sum.json"
    },
    {
      "snapshot": "haybarn-2.0.0-rc11",
      "observed": true,
      "overloadCount": 8,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/haybarn-2.0.0-rc11/functions/sum.json"
    },
    {
      "snapshot": "haybarn-2.0.0-rc8",
      "observed": true,
      "overloadCount": 8,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/haybarn-2.0.0-rc8/functions/sum.json"
    },
    {
      "snapshot": "haybarn-1.5.5-rc3",
      "observed": true,
      "overloadCount": 8,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/haybarn-1.5.5-rc3/functions/sum.json"
    },
    {
      "snapshot": "haybarn-1.5.6-rc6",
      "observed": true,
      "overloadCount": 8,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/haybarn-1.5.6-rc6/functions/sum.json"
    },
    {
      "snapshot": "duckdb-2.0.0",
      "observed": true,
      "overloadCount": 8,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/duckdb-2.0.0/functions/sum.json"
    },
    {
      "snapshot": "duckdb-1.5.6",
      "observed": true,
      "overloadCount": 8,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/duckdb-1.5.6/functions/sum.json"
    },
    {
      "snapshot": "duckdb-1.5.5",
      "observed": true,
      "overloadCount": 8,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/duckdb-1.5.5/functions/sum.json"
    },
    {
      "snapshot": "duckdb-1.4.4",
      "observed": true,
      "overloadCount": 8,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-5d3b17dd154d827e",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/duckdb-1.4.4/functions/sum.json"
    },
    {
      "snapshot": "duckdb-1.3.2",
      "observed": true,
      "overloadCount": 7,
      "matchingOverloadIds": [
        "overload-364e1499a3b31b6d",
        "overload-f631ee5353c08dd7",
        "overload-707c3ce29eb71f2a",
        "overload-e815fe648ba59f1f",
        "overload-696623bb8b4b05c9",
        "overload-b0cae1c0988f2b33",
        "overload-d79f5dbb9d7776cf"
      ],
      "json": "/products/haybarn/functions/api/v1/duckdb-1.3.2/functions/sum.json"
    }
  ]
}
