Skip to main content

DB_Table.select_columns

select_columnscolumns reordercase_sensitivityerror_on_missing_columnson_problems

Group: Selections
Aliases: select fields

Documentation

Returns a new table with a chosen subset of columns, as specified by the columns, from the input table. Any unmatched input columns will be dropped from the output.

Arguments

  • columns: Specifies columns by a single instance or Vector of names; indexes or regular expressions to match names; or a By_Type selector to choose columns by type. Note: specifying columns by type ignores size and precision.
  • reorder: By default, or if set to False, columns in the output will be in the same order as in the input table. If True, the order in the output table will match the order in the columns list. If a column is matched by multiple selectors in reorder mode, it will be placed at the position of the first one matched.
  • case_sensitivity: Controls whether to be case sensitive when matching column names.
  • error_on_missing_columns: Specifies if a missing input column should result in an error regardless of the on_problems settings. Defaults to True.
  • on_problems: Specifies how to handle problems if they occur, reporting them as warnings by default.

Examples

Select columns by name.

      table.select_columns ["bar", "foo"]

Select columns using names passed as a Vector.

      table.select_columns ["bar", "foo"]

Select columns matching a regular expression.

      table.select_columns "foo.+".to_regex case_sensitivity=Case_Sensitivity.Insensitive

Select the first two columns and the last column, moving the last one to front.

      table.select_columns [-1, 0, 1] reorder=True

Select integer columns.

      table.select_columns [..By_Type ..Integer]

Errors

  • If there are no columns in the output table, a No_Output_Columns is raised as an error regardless of the problem behavior, because it is not possible to create a table without any columns.
  • If a column in columns is not in the input table, a Missing_Input_Columns is raised as an error, unless error_on_missing_columns is set to False, in which case the problem is reported according to the on_problems setting.