{
    "mode": "man",
    "parameter": "ALTER_VIEW",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/ALTER_VIEW/7/json",
    "generated": "2026-10-07T14:47:22Z",
    "synopsis": "ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] columnname SET DEFAULT expression\nALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] columnname DROP DEFAULT\nALTER VIEW [ IF EXISTS ] name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nALTER VIEW [ IF EXISTS ] name RENAME [ COLUMN ] columnname TO newcolumnname\nALTER VIEW [ IF EXISTS ] name RENAME TO newname\nALTER VIEW [ IF EXISTS ] name SET SCHEMA newschema\nALTER VIEW [ IF EXISTS ] name SET ( viewoptionname [= viewoptionvalue] [, ... ] )\nALTER VIEW [ IF EXISTS ] name RESET ( viewoptionname [, ... ] )",
    "sections": {
        "NAME": {
            "content": "ALTERVIEW - change the definition of a view\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] columnname SET DEFAULT expression\nALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] columnname DROP DEFAULT\nALTER VIEW [ IF EXISTS ] name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nALTER VIEW [ IF EXISTS ] name RENAME [ COLUMN ] columnname TO newcolumnname\nALTER VIEW [ IF EXISTS ] name RENAME TO newname\nALTER VIEW [ IF EXISTS ] name SET SCHEMA newschema\nALTER VIEW [ IF EXISTS ] name SET ( viewoptionname [= viewoptionvalue] [, ... ] )\nALTER VIEW [ IF EXISTS ] name RESET ( viewoptionname [, ... ] )\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "ALTER VIEW changes various auxiliary properties of a view. (If you want to modify the view's\ndefining query, use CREATE OR REPLACE VIEW.)\n\nYou must own the view to use ALTER VIEW. To change a view's schema, you must also have CREATE\nprivilege on the new schema. To alter the owner, you must be able to SET ROLE to the new\nowning role, and that role must have CREATE privilege on the view's schema. (These\nrestrictions enforce that altering the owner doesn't do anything you couldn't do by dropping\nand recreating the view. However, a superuser can alter ownership of any view anyway.)\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "name\nThe name (optionally schema-qualified) of an existing view.\n\ncolumnname\nName of an existing column.\n\nnewcolumnname\nNew name for an existing column.\n\nIF EXISTS\nDo not throw an error if the view does not exist. A notice is issued in this case.\n\nSET/DROP DEFAULT\nThese forms set or remove the default value for a column. A view column's default value\nis substituted into any INSERT or UPDATE command whose target is the view, before\napplying any rules or triggers for the view. The view's default will therefore take\nprecedence over any default values from underlying relations.\n\nnewowner\nThe user name of the new owner of the view.\n\nnewname\nThe new name for the view.\n\nnewschema\nThe new schema for the view.\n\nSET ( viewoptionname [= viewoptionvalue] [, ... ] )\nRESET ( viewoptionname [, ... ] )\nSets or resets a view option. Currently supported options are:\n\ncheckoption (enum)\nChanges the check option of the view. The value must be local or cascaded.\n\nsecuritybarrier (boolean)\nChanges the security-barrier property of the view. The value must be a Boolean value,\nsuch as true or false.\n\nsecurityinvoker (boolean)\nChanges the security-invoker property of the view. The value must be a Boolean value,\nsuch as true or false.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "For historical reasons, ALTER TABLE can be used with views too; but the only variants of\nALTER TABLE that are allowed with views are equivalent to the ones shown above.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To rename the view foo to bar:\n\nALTER VIEW foo RENAME TO bar;\n\nTo attach a default column value to an updatable view:\n\nCREATE TABLE basetable (id int, ts timestamptz);\nCREATE VIEW aview AS SELECT * FROM basetable;\nALTER VIEW aview ALTER COLUMN ts SET DEFAULT now();\nINSERT INTO basetable(id) VALUES(1);  -- ts will receive a NULL\nINSERT INTO aview(id) VALUES(2);  -- ts will receive the current time\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "ALTER VIEW is a PostgreSQL extension of the SQL standard.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "CREATE VIEW (CREATEVIEW(7)), DROP VIEW (DROPVIEW(7))\n\nPostgreSQL 16.14                                2026                                   ALTER VIEW(7)",
            "subsections": []
        }
    },
    "summary": "ALTERVIEW - change the definition of a view",
    "flags": [],
    "examples": [
        "To rename the view foo to bar:",
        "ALTER VIEW foo RENAME TO bar;",
        "To attach a default column value to an updatable view:",
        "CREATE TABLE basetable (id int, ts timestamptz);",
        "CREATE VIEW aview AS SELECT * FROM basetable;",
        "ALTER VIEW aview ALTER COLUMN ts SET DEFAULT now();",
        "INSERT INTO basetable(id) VALUES(1);  -- ts will receive a NULL",
        "INSERT INTO aview(id) VALUES(2);  -- ts will receive the current time"
    ],
    "see_also": [
        {
            "name": "CREATEVIEW",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATEVIEW/7/json"
        },
        {
            "name": "DROPVIEW",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DROPVIEW/7/json"
        },
        {
            "name": "VIEW",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/VIEW/7/json"
        }
    ]
}