Updated on 2024-06-03 GMT+08:00

DROP RULE

Function

Deletes a rewriting rule.

Syntax

DROP RULE [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ];

Parameter Description

  • IF EXISTS

    If the rule does not exist, a notice is thrown.

  • name

    Name of an existing rule to be deleted.

  • table_name

    Name of the table to which the rule applies.

  • CASCADE

    Automatically cascade deletes objects that depend on this rule.

  • RESTRICT

    Refuses to delete the rule if any objects depend on it. The default value is used.

Examples

-- Create the def_test table and the def_view_test view for creating rules.
gaussdb=# CREATE TABLE def_test (
c1 int4 DEFAULT 5,
c2 text DEFAULT 'initial_default'
);
gaussdb=# CREATE VIEW def_view_test AS SELECT * FROM def_test;
-- Create the rule def_view_test_ins.
gaussdb=# CREATE RULE def_view_test_ins AS
gaussdb=# ON INSERT TO def_view_test
gaussdb=#DO INSTEAD INSERT INTO def_test SELECT new.*;
-- Delete the rule def_view_test_ins.
gaussdb=# DROP RULE def_view_test_ins ON def_view_test;
-- Delete the def_test table and the def_view_test view.
gaussdb=# DROP VIEW def_view_test;
gaussdb=# DROP TABLE def_test;

Helpful Links

CREATE RULE