{
    "content": [
        {
            "type": "text",
            "text": "# ALTER_FOREIGN_TABLE (man)\n\n## NAME\n\nALTERFOREIGNTABLE - change the definition of a foreign table\n\n## SYNOPSIS\n\nALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ]\naction [, ... ]\nALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ]\nRENAME [ COLUMN ] columnname TO newcolumnname\nALTER FOREIGN TABLE [ IF EXISTS ] name\nRENAME TO newname\nALTER FOREIGN TABLE [ IF EXISTS ] name\nSET SCHEMA newschema\nwhere action is one of:\nADD [ COLUMN ] [ IF NOT EXISTS ] columnname datatype [ COLLATE collation ] [ columnconstraint [ ... ] ]\nDROP [ COLUMN ] [ IF EXISTS ] columnname [ RESTRICT | CASCADE ]\nALTER [ COLUMN ] columnname [ SET DATA ] TYPE datatype [ COLLATE collation ]\nALTER [ COLUMN ] columnname SET DEFAULT expression\nALTER [ COLUMN ] columnname DROP DEFAULT\nALTER [ COLUMN ] columnname { SET | DROP } NOT NULL\nALTER [ COLUMN ] columnname SET STATISTICS integer\nALTER [ COLUMN ] columnname SET ( attributeoption = value [, ... ] )\nALTER [ COLUMN ] columnname RESET ( attributeoption [, ... ] )\nALTER [ COLUMN ] columnname SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }\nALTER [ COLUMN ] columnname OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])\nADD tableconstraint [ NOT VALID ]\nVALIDATE CONSTRAINT constraintname\nDROP CONSTRAINT [ IF EXISTS ]  constraintname [ RESTRICT | CASCADE ]\nDISABLE TRIGGER [ triggername | ALL | USER ]\nENABLE TRIGGER [ triggername | ALL | USER ]\nENABLE REPLICA TRIGGER triggername\nENABLE ALWAYS TRIGGER triggername\nSET WITHOUT OIDS\nINHERIT parenttable\nNO INHERIT parenttable\nOWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nOPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])\n\n## DESCRIPTION\n\nALTER FOREIGN TABLE changes the definition of an existing foreign table. There are several\nsubforms:\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS**\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "ALTER_FOREIGN_TABLE",
        "section": "",
        "mode": "man",
        "summary": "ALTERFOREIGNTABLE - change the definition of a foreign table",
        "synopsis": "ALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ]\naction [, ... ]\nALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ]\nRENAME [ COLUMN ] columnname TO newcolumnname\nALTER FOREIGN TABLE [ IF EXISTS ] name\nRENAME TO newname\nALTER FOREIGN TABLE [ IF EXISTS ] name\nSET SCHEMA newschema\nwhere action is one of:\nADD [ COLUMN ] [ IF NOT EXISTS ] columnname datatype [ COLLATE collation ] [ columnconstraint [ ... ] ]\nDROP [ COLUMN ] [ IF EXISTS ] columnname [ RESTRICT | CASCADE ]\nALTER [ COLUMN ] columnname [ SET DATA ] TYPE datatype [ COLLATE collation ]\nALTER [ COLUMN ] columnname SET DEFAULT expression\nALTER [ COLUMN ] columnname DROP DEFAULT\nALTER [ COLUMN ] columnname { SET | DROP } NOT NULL\nALTER [ COLUMN ] columnname SET STATISTICS integer\nALTER [ COLUMN ] columnname SET ( attributeoption = value [, ... ] )\nALTER [ COLUMN ] columnname RESET ( attributeoption [, ... ] )\nALTER [ COLUMN ] columnname SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }\nALTER [ COLUMN ] columnname OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])\nADD tableconstraint [ NOT VALID ]\nVALIDATE CONSTRAINT constraintname\nDROP CONSTRAINT [ IF EXISTS ]  constraintname [ RESTRICT | CASCADE ]\nDISABLE TRIGGER [ triggername | ALL | USER ]\nENABLE TRIGGER [ triggername | ALL | USER ]\nENABLE REPLICA TRIGGER triggername\nENABLE ALWAYS TRIGGER triggername\nSET WITHOUT OIDS\nINHERIT parenttable\nNO INHERIT parenttable\nOWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nOPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "To mark a column as not-null:",
            "ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL;",
            "To change options of a foreign table:",
            "ALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2 'value2', DROP opt3);"
        ],
        "see_also": [
            {
                "name": "CREATEFOREIGNTABLE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/CREATEFOREIGNTABLE/7/json"
            },
            {
                "name": "DROPFOREIGNTABLE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/DROPFOREIGNTABLE/7/json"
            },
            {
                "name": "TABLE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/TABLE/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 35,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 110,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 55,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "ALTERFOREIGNTABLE - change the definition of a foreign table\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "ALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ]\naction [, ... ]\nALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ]\nRENAME [ COLUMN ] columnname TO newcolumnname\nALTER FOREIGN TABLE [ IF EXISTS ] name\nRENAME TO newname\nALTER FOREIGN TABLE [ IF EXISTS ] name\nSET SCHEMA newschema\n\nwhere action is one of:\n\nADD [ COLUMN ] [ IF NOT EXISTS ] columnname datatype [ COLLATE collation ] [ columnconstraint [ ... ] ]\nDROP [ COLUMN ] [ IF EXISTS ] columnname [ RESTRICT | CASCADE ]\nALTER [ COLUMN ] columnname [ SET DATA ] TYPE datatype [ COLLATE collation ]\nALTER [ COLUMN ] columnname SET DEFAULT expression\nALTER [ COLUMN ] columnname DROP DEFAULT\nALTER [ COLUMN ] columnname { SET | DROP } NOT NULL\nALTER [ COLUMN ] columnname SET STATISTICS integer\nALTER [ COLUMN ] columnname SET ( attributeoption = value [, ... ] )\nALTER [ COLUMN ] columnname RESET ( attributeoption [, ... ] )\nALTER [ COLUMN ] columnname SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }\nALTER [ COLUMN ] columnname OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])\nADD tableconstraint [ NOT VALID ]\nVALIDATE CONSTRAINT constraintname\nDROP CONSTRAINT [ IF EXISTS ]  constraintname [ RESTRICT | CASCADE ]\nDISABLE TRIGGER [ triggername | ALL | USER ]\nENABLE TRIGGER [ triggername | ALL | USER ]\nENABLE REPLICA TRIGGER triggername\nENABLE ALWAYS TRIGGER triggername\nSET WITHOUT OIDS\nINHERIT parenttable\nNO INHERIT parenttable\nOWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nOPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ])\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "ALTER FOREIGN TABLE changes the definition of an existing foreign table. There are several\nsubforms:\n\nADD [ COLUMN ] [ IF NOT EXISTS ]\nThis form adds a new column to the foreign table, using the same syntax as CREATE FOREIGN\nTABLE. If IF NOT EXISTS is specified and a column already exists with this name, no error\nis thrown. Unlike the case when adding a column to a regular table, nothing happens to\nthe underlying storage: this action simply declares that some new column is now\naccessible through the foreign table.\n\nDROP [ COLUMN ] [ IF EXISTS ]\nThis form drops a column from a foreign table. You will need to say CASCADE if anything\noutside the table depends on the column; for example, views. If IF EXISTS is specified\nand the column does not exist, no error is thrown. In this case a notice is issued\ninstead.\n\nSET DATA TYPE\nThis form changes the type of a column of a foreign table. Again, this has no effect on\nany underlying storage: this action simply changes the type that PostgreSQL believes the\ncolumn to have.\n\nSET/DROP DEFAULT\nThese forms set or remove the default value for a column. Default values only apply in\nsubsequent INSERT or UPDATE commands; they do not cause rows already in the table to\nchange.\n\nSET/DROP NOT NULL\nMark a column as allowing, or not allowing, null values.\n\nSET STATISTICS\nThis form sets the per-column statistics-gathering target for subsequent ANALYZE\noperations. See the similar form of ALTER TABLE for more details.\n\nSET ( attributeoption = value [, ... ] )\nRESET ( attributeoption [, ... ] )\nThis form sets or resets per-attribute options. See the similar form of ALTER TABLE for\nmore details.\n\nSET STORAGE\nThis form sets the storage mode for a column. See the similar form of ALTER TABLE for\nmore details. Note that the storage mode has no effect unless the table's foreign-data\nwrapper chooses to pay attention to it.\n\nADD tableconstraint [ NOT VALID ]\nThis form adds a new constraint to a foreign table, using the same syntax as CREATE\nFOREIGN TABLE. Currently only CHECK constraints are supported.\n\nUnlike the case when adding a constraint to a regular table, nothing is done to verify\nthe constraint is correct; rather, this action simply declares that some new condition\nshould be assumed to hold for all rows in the foreign table. (See the discussion in\nCREATE FOREIGN TABLE.) If the constraint is marked NOT VALID, then it isn't assumed to\nhold, but is only recorded for possible future use.\n\nVALIDATE CONSTRAINT\nThis form marks as valid a constraint that was previously marked as NOT VALID. No action\nis taken to verify the constraint, but future queries will assume that it holds.\n\nDROP CONSTRAINT [ IF EXISTS ]\nThis form drops the specified constraint on a foreign table. If IF EXISTS is specified\nand the constraint does not exist, no error is thrown. In this case a notice is issued\ninstead.\n\nDISABLE/ENABLE [ REPLICA | ALWAYS ] TRIGGER\nThese forms configure the firing of trigger(s) belonging to the foreign table. See the\nsimilar form of ALTER TABLE for more details.\n\nSET WITHOUT OIDS\nBackward compatibility syntax for removing the oid system column. As oid system columns\ncannot be added anymore, this never has an effect.\n\nINHERIT parenttable\nThis form adds the target foreign table as a new child of the specified parent table. See\nthe similar form of ALTER TABLE for more details.\n\nNO INHERIT parenttable\nThis form removes the target foreign table from the list of children of the specified\nparent table.\n\nOWNER\nThis form changes the owner of the foreign table to the specified user.\n\nOPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] )\nChange options for the foreign table or one of its columns.  ADD, SET, and DROP specify\nthe action to be performed.  ADD is assumed if no operation is explicitly specified.\nDuplicate option names are not allowed (although it's OK for a table option and a column\noption to have the same name). Option names and values are also validated using the\nforeign data wrapper library.\n\nRENAME\nThe RENAME forms change the name of a foreign table or the name of an individual column\nin a foreign table.\n\nSET SCHEMA\nThis form moves the foreign table into another schema.\n\nAll the actions except RENAME and SET SCHEMA can be combined into a list of multiple\nalterations to apply in parallel. For example, it is possible to add several columns and/or\nalter the type of several columns in a single command.\n\nIf the command is written as ALTER FOREIGN TABLE IF EXISTS ...  and the foreign table does\nnot exist, no error is thrown. A notice is issued in this case.\n\nYou must own the table to use ALTER FOREIGN TABLE. To change the schema of a foreign table,\nyou must also have CREATE privilege on the new schema. To alter the owner, you must also be a\ndirect or indirect member of the new owning role, and that role must have CREATE privilege on\nthe table's schema. (These restrictions enforce that altering the owner doesn't do anything\nyou couldn't do by dropping and recreating the table. However, a superuser can alter\nownership of any table anyway.) To add a column or alter a column type, you must also have\nUSAGE privilege on the data type.\n",
                "subsections": []
            },
            "PARAMETERS": {
                "content": "name\nThe name (possibly schema-qualified) of an existing foreign table to alter. If ONLY is\nspecified before the table name, only that table is altered. If ONLY is not specified,\nthe table and all its descendant tables (if any) are altered. Optionally, * can be\nspecified after the table name to explicitly indicate that descendant tables are\nincluded.\n\ncolumnname\nName of a new or existing column.\n\nnewcolumnname\nNew name for an existing column.\n\nnewname\nNew name for the table.\n\ndatatype\nData type of the new column, or new data type for an existing column.\n\ntableconstraint\nNew table constraint for the foreign table.\n\nconstraintname\nName of an existing constraint to drop.\n\nCASCADE\nAutomatically drop objects that depend on the dropped column or constraint (for example,\nviews referencing the column), and in turn all objects that depend on those objects (see\nSection 5.14).\n\nRESTRICT\nRefuse to drop the column or constraint if there are any dependent objects. This is the\ndefault behavior.\n\ntriggername\nName of a single trigger to disable or enable.\n\nALL\nDisable or enable all triggers belonging to the foreign table. (This requires superuser\nprivilege if any of the triggers are internally generated triggers. The core system does\nnot add such triggers to foreign tables, but add-on code could do so.)\n\nUSER\nDisable or enable all triggers belonging to the foreign table except for internally\ngenerated triggers.\n\nparenttable\nA parent table to associate or de-associate with this foreign table.\n\nnewowner\nThe user name of the new owner of the table.\n\nnewschema\nThe name of the schema to which the table will be moved.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "The key word COLUMN is noise and can be omitted.\n\nConsistency with the foreign server is not checked when a column is added or removed with ADD\nCOLUMN or DROP COLUMN, a NOT NULL or CHECK constraint is added, or a column type is changed\nwith SET DATA TYPE. It is the user's responsibility to ensure that the table definition\nmatches the remote side.\n\nRefer to CREATE FOREIGN TABLE for a further description of valid parameters.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "To mark a column as not-null:\n\nALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL;\n\nTo change options of a foreign table:\n\nALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2 'value2', DROP opt3);\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "The forms ADD, DROP, and SET DATA TYPE conform with the SQL standard. The other forms are\nPostgreSQL extensions of the SQL standard. Also, the ability to specify more than one\nmanipulation in a single ALTER FOREIGN TABLE command is an extension.\n\nALTER FOREIGN TABLE DROP COLUMN can be used to drop the only column of a foreign table,\nleaving a zero-column table. This is an extension of SQL, which disallows zero-column foreign\ntables.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "CREATE FOREIGN TABLE (CREATEFOREIGNTABLE(7)), DROP FOREIGN TABLE (DROPFOREIGNTABLE(7))\n\n\n\nPostgreSQL 14.23                                2026                          ALTER FOREIGN TABLE(7)",
                "subsections": []
            }
        }
    }
}