{
    "content": [
        {
            "type": "text",
            "text": "# DELETE (man)\n\n## NAME\n\nDELETE - delete rows of a table\n\n## SYNOPSIS\n\n[ WITH [ RECURSIVE ] withquery [, ...] ]\nDELETE FROM [ ONLY ] tablename [ * ] [ [ AS ] alias ]\n[ USING fromitem [, ...] ]\n[ WHERE condition | WHERE CURRENT OF cursorname ]\n[ RETURNING { * | outputexpression [ [ AS ] outputname ] } [, ...] ]\n\n## DESCRIPTION\n\nDELETE deletes rows that satisfy the WHERE clause from the specified table. If the WHERE\nclause is absent, the effect is to delete all rows in the table. The result is a valid, but\nempty table.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS**\n- **OUTPUTS**\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "DELETE",
        "section": "",
        "mode": "man",
        "summary": "DELETE - delete rows of a table",
        "synopsis": "[ WITH [ RECURSIVE ] withquery [, ...] ]\nDELETE FROM [ ONLY ] tablename [ * ] [ [ AS ] alias ]\n[ USING fromitem [, ...] ]\n[ WHERE condition | WHERE CURRENT OF cursorname ]\n[ RETURNING { * | outputexpression [ [ AS ] outputname ] } [, ...] ]",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "Delete all films but musicals:",
            "DELETE FROM films WHERE kind <> 'Musical';",
            "Clear the table films:",
            "DELETE FROM films;",
            "Delete completed tasks, returning full details of the deleted rows:",
            "DELETE FROM tasks WHERE status = 'DONE' RETURNING *;",
            "Delete the row of tasks on which the cursor ctasks is currently positioned:",
            "DELETE FROM tasks WHERE CURRENT OF ctasks;"
        ],
        "see_also": [
            {
                "name": "TRUNCATE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/TRUNCATE/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 42,
                "subsections": []
            },
            {
                "name": "OUTPUTS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "DELETE - delete rows of a table\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "[ WITH [ RECURSIVE ] withquery [, ...] ]\nDELETE FROM [ ONLY ] tablename [ * ] [ [ AS ] alias ]\n[ USING fromitem [, ...] ]\n[ WHERE condition | WHERE CURRENT OF cursorname ]\n[ RETURNING { * | outputexpression [ [ AS ] outputname ] } [, ...] ]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "DELETE deletes rows that satisfy the WHERE clause from the specified table. If the WHERE\nclause is absent, the effect is to delete all rows in the table. The result is a valid, but\nempty table.\n\nTip\nTRUNCATE provides a faster mechanism to remove all rows from a table.\n\nThere are two ways to delete rows in a table using information contained in other tables in\nthe database: using sub-selects, or specifying additional tables in the USING clause. Which\ntechnique is more appropriate depends on the specific circumstances.\n\nThe optional RETURNING clause causes DELETE to compute and return value(s) based on each row\nactually deleted. Any expression using the table's columns, and/or columns of other tables\nmentioned in USING, can be computed. The syntax of the RETURNING list is identical to that of\nthe output list of SELECT.\n\nYou must have the DELETE privilege on the table to delete from it, as well as the SELECT\nprivilege for any table in the USING clause or whose values are read in the condition.\n",
                "subsections": []
            },
            "PARAMETERS": {
                "content": "withquery\nThe WITH clause allows you to specify one or more subqueries that can be referenced by\nname in the DELETE query. See Section 7.8 and SELECT(7) for details.\n\ntablename\nThe name (optionally schema-qualified) of the table to delete rows from. If ONLY is\nspecified before the table name, matching rows are deleted from the named table only. If\nONLY is not specified, matching rows are also deleted from any tables inheriting from the\nnamed table. Optionally, * can be specified after the table name to explicitly indicate\nthat descendant tables are included.\n\nalias\nA substitute name for the target table. When an alias is provided, it completely hides\nthe actual name of the table. For example, given DELETE FROM foo AS f, the remainder of\nthe DELETE statement must refer to this table as f not foo.\n\nfromitem\nA table expression allowing columns from other tables to appear in the WHERE condition.\nThis uses the same syntax as the FROM clause of a SELECT statement; for example, an alias\nfor the table name can be specified. Do not repeat the target table as a fromitem unless\nyou wish to set up a self-join (in which case it must appear with an alias in the\nfromitem).\n\ncondition\nAn expression that returns a value of type boolean. Only rows for which this expression\nreturns true will be deleted.\n\ncursorname\nThe name of the cursor to use in a WHERE CURRENT OF condition. The row to be deleted is\nthe one most recently fetched from this cursor. The cursor must be a non-grouping query\non the DELETE's target table. Note that WHERE CURRENT OF cannot be specified together\nwith a Boolean condition. See DECLARE(7) for more information about using cursors with\nWHERE CURRENT OF.\n\noutputexpression\nAn expression to be computed and returned by the DELETE command after each row is\ndeleted. The expression can use any column names of the table named by tablename or\ntable(s) listed in USING. Write * to return all columns.\n\noutputname\nA name to use for a returned column.\n",
                "subsections": []
            },
            "OUTPUTS": {
                "content": "On successful completion, a DELETE command returns a command tag of the form\n\nDELETE count\n\nThe count is the number of rows deleted. Note that the number may be less than the number of\nrows that matched the condition when deletes were suppressed by a BEFORE DELETE trigger. If\ncount is 0, no rows were deleted by the query (this is not considered an error).\n\nIf the DELETE command contains a RETURNING clause, the result will be similar to that of a\nSELECT statement containing the columns and values defined in the RETURNING list, computed\nover the row(s) deleted by the command.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "PostgreSQL lets you reference columns of other tables in the WHERE condition by specifying\nthe other tables in the USING clause. For example, to delete all films produced by a given\nproducer, one can do:\n\nDELETE FROM films USING producers\nWHERE producerid = producers.id AND producers.name = 'foo';\n\nWhat is essentially happening here is a join between films and producers, with all\nsuccessfully joined films rows being marked for deletion. This syntax is not standard. A more\nstandard way to do it is:\n\nDELETE FROM films\nWHERE producerid IN (SELECT id FROM producers WHERE name = 'foo');\n\nIn some cases the join style is easier to write or faster to execute than the sub-select\nstyle.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "Delete all films but musicals:\n\nDELETE FROM films WHERE kind <> 'Musical';\n\nClear the table films:\n\nDELETE FROM films;\n\nDelete completed tasks, returning full details of the deleted rows:\n\nDELETE FROM tasks WHERE status = 'DONE' RETURNING *;\n\nDelete the row of tasks on which the cursor ctasks is currently positioned:\n\nDELETE FROM tasks WHERE CURRENT OF ctasks;\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "This command conforms to the SQL standard, except that the USING and RETURNING clauses are\nPostgreSQL extensions, as is the ability to use WITH with DELETE.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "TRUNCATE(7)\n\n\n\nPostgreSQL 14.23                                2026                                       DELETE(7)",
                "subsections": []
            }
        }
    }
}