Skip to main content

1E 24.1 (SaaS)

Utilities.GetColumns

Module

Utilities

Method

Utilities

Library

Core

Action

List the columns in a table, giving the names and data types.

Parameters

  • Table (table): The table variable whose column information we want.

  • DeepSearch (boolean, default true): If false, assume for efficiency that the first row contains all the columns that are in the table, otherwise if true (the safer but slower option) then scan all rows in case some are incomplete.

Warning

Only use 'false' if cells cannot be null and no rows can have 'missing' columns (i.e. not a 'jagged' table).

Return values

  • ColumnName (string): The name of a column in the input table.

    Note

    The columns are sorted alphabetically by name, to make them more readable and for consistency.

  • DataType (string): One of: "bool", "integer", "float", string" or "datetime" (for an ISO-8601 time-point), unless the 'type' is null in which case a NULL cell is returned.

    Note

    Time-points are only used internally in the 1E Client. Neither SQL nor JSON support them, where they appear as ordinary strings. Also, JSON has no boolean type; integers of 0 and 1 are the equivalent.

Example

Example 1 (where the DeepSearch value does not matter because there is just 1 row).

    @table = SELECT "string" as stringCol, 42 AS intCol, true AS boolCol, 1.23 AS doubleCol, NULL AS nullCol, "2023-10-19T14:07:00.895Z" AS timepointCol;
    Utilities.GetColumns(Table:@table);

Returns:

    ColumnName      DataType
    ==========      ========
    "boolCol"       "integer"
    "doubleCol"     "float"
    "intCol"        "integer"
    "nullCol"       NULL
    "stringCol"     "string"
    "timepointCol"  "string"

Example 2 (Another way to scan just the first row for column names).

   @myTable = Whatever.GetSomeData();
   @firstRow = SELECT * FROM @myTable LIMIT 1;
   @cols = Utilities.GetColumns(Table: @firstRow);

Platforms

  • Windows

  • Linux

  • MacOS.

Notes

  • Assumptions: (a) column names are not duplicated; (b) all cells in a given column have the same type (NULL cells are also allowed).

  • This method is useful for when tables have been created dynamically using, for example, the Utilities.TableFromJson method, or for when tables may have different columns depending on the version of the 1E Client.

  • New in v24.1