Q

Random posts about ... stuff

View the Project on GitHub rMaxiQp/rMaxiQp.github.io

12 June 2020

PostgeSQL Delete Query

by Q

DELETE removes rows that satisfy the WHERE clause from the specified table. If the WHERE clause is not specified, all rows will be moved.

Syntax

[ WITH [ RECURSIVE ] with_query [, ...] ]
DELETE FROM [ ONLY ] table_name [ * ] [ [ AS ] alias ]
    [ USING from_item [, ...] ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

Example

Delete all logs but the ones on 2009/06/01:

DELETE FROM
    logs
WHERE
    date <> '2009-06-01';

Clear the table logs:

DELETE FROM logs;

References:

Updated: 12 June 2020
tags: Language