Skip to main content

DB_Table.format

formatcolumnsformatlocaleerror_on_missing_columnson_problems

Group: Conversions

Documentation

Formats DB_Columns within a Table using a format string, Date_Time_Formatter, or DB_Column of format strings.

Arguments

  • columns: The columns to format. The columns can have different types, but all columns must be compatible with any provided format value.
  • format: The type-dependent format string to use to format the values. If format is "" or Nothing, .to_text is used to format the value. In case of date/time columns, the format can also be a Date_Time_Formatter. If format is a DB_Column, it must be a text column.
  • locale: The locale in which the format should be interpreted. If a Date_Time_Formatter is provided for format and the locale is set to anything else than Locale.default, then that locale will override the formatters locale.
  • 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 if a problem occurs, raising as a warning by default.

Examples

Format the first and last boolean columns as 'Yes'/'No'.

      table.format columns=[0, -1] format="Yes|No"

Format dates in a column using the format yyyyMMdd.

      table.format "birthday" "yyyyMMdd"

Format all columns in the table using the default formatter.

      table.format

Errors

  • 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.
  • If a provided format value is not compatible with all selected columns, an Illegal_Argument error will be thrown, or a Date_Time_Format_Parse_Error in the case of a badly-formed date/time format.
  • If no columns have been selected for formatting, a No_Input_Columns_Selected error is raised.

Remarks

Supported Types

  • Value_Type.Date
  • Value_Type.Date_Time
  • Value_Type.Time
  • Value_Type.Integer
  • Value_Type.Float
  • Value_Type.Boolean

Value_Type.Date, Value_Type.Date_Time, Value_Type.Time format strings

See Date_Time_Formatter for more details.

Value_Type.Integer, Value_Type.Float format strings

Numeric format strings are specified by the Java DecimalFormat class. See https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html for a complete format specification.

Value_Type.Boolean format strings

Format strings for Boolean consist of two values that represent true and false, separated by a |.