Polyglot SQL API Documentation - v0.2.0
    Preparing search index...

    Function getInferredType

    • Get the inferred data type from an Expression, if it has been type-annotated.

      After calling annotateTypes(), value-producing expressions (columns, operators, functions, casts, etc.) carry an inferred_type field with their resolved SQL type.

      Parameters

      Returns DataType | undefined

      The inferred DataType, or undefined if not annotated or not a value-producing expression.

      const result = annotateTypes("SELECT 1 + 2", Dialect.Generic);
      if (result.success) {
      const addExpr = result.ast![0]; // the SELECT
      // Navigate to the "1 + 2" expression and check its type:
      const dt = getInferredType(someExpr);
      // dt => { data_type: "int", length: null, integer_spelling: false }
      }