Updated on 2025-05-29 GMT+08:00

ALTER FOREIGN TABLE

Description

Modifies a foreign table.

Precautions

When multi-layer quotation marks are used for sensitive columns (such as password and secret_access_key) in OPTIONS, the semantics is different from that in the scenario where quotation marks are not used. Therefore, sensitive columns are not identified for anonymization.

In the multi-tenancy scenario, only the initial user can run the ALTER FOREIGN TABLE command in a PDB.

Syntax

  • Change the attributes of a foreign table.
    ALTER FOREIGN TABLE [ IF EXISTS ]  table_name
        OPTIONS ( {[ ADD | SET | DROP ] option ['value']}[, ... ]);

  • Change the column options of the foreign table.
    ALTER FOREIGN TABLE [ IF EXISTS ] table_name
        ALTER column_name OPTIONS;

Parameters

  • table_name

    Specifies the name of an existing foreign table to be modified.

    Value range: an existing foreign table name.

  • option

    Specifies the option of a foreign table or foreign table column to be modified. ADD, SET, and DROP are operations to be performed. If no operation is set explicitly, the default value ADD is used. The option name must be unique (although table options and table column options can share the same name). The name and value of the option are also validated by a class library of a foreign data wrapper.

    • Options supported by file_fdw are as follows:
      • filename

        File to be read. This parameter is required and must be an absolute path.

      • format

        File format of the remote server, which is the same as the FORMAT option in the COPY statement. The value can be text, csv, binary, or fixed.

      • header

        Specifies whether a specified file has a header, which is the same as the HEADER option of the COPY statement.

        • delimiter

          File delimiter, which is the same as the DELIMITER option of the COPY statement.

        • quote

          Quote character of a file, which is the same as the QUOTE option of the COPY statement.

        • escape

          Escape character of a file, which is the same as the ESCAPE option of the COPY statement.

        • null

          Null string of a file, which is the same as the NULL option of the COPY statement.

        • encoding

          Encoding of a file, which is the same as the ENCODING option of the COPY statement.

        • force_not_null

          This is a Boolean option. If it is true, the value of the declared field cannot be an empty string. This option is the same as the FORCE_NOT_NULL option of the COPY statement.

      For details about how to use file_fdw, see section "Foreign Data Wrapper > file_fdw" in Feature Guide.

  • value

    Specifies the new value of option.

  • column_name

    Specifies the name of an existing column.

    Value range: a string. It must comply with the naming convention in Identifier Naming Conventions.

Examples

-- Create a server.
gaussdb=# CREATE SERVER my_server FOREIGN DATA WRAPPER log_fdw;

-- Create a foreign table.
gaussdb=# CREATE FOREIGN TABLE foreign_tbl (col1 text) SERVER my_server OPTIONS (logtype 'gs_log');

-- Change the attributes of the foreign table.
gaussdb=# ALTER FOREIGN TABLE foreign_tbl OPTIONS (ADD latest_files '2');
gaussdb=# ALTER FOREIGN TABLE foreign_tbl OPTIONS ( SET latest_files '5');
gaussdb=# ALTER FOREIGN TABLE foreign_tbl OPTIONS ( DROP latest_files);

-- Delete the foreign table.
gaussdb=# DROP FOREIGN TABLE foreign_tbl;

-- Delete the server.
gaussdb=# DROP SERVER my_server;