Skip to content

CAST/TRY_CAST/CONVERT reject bare literal operands — CAST('125' AS BIGINT) does not parse #267

Description

@fupelaqu

CAST('125' AS BIGINT) is a parse error, and so is every other conversion of a bare literal: no conversion production accepts a literal operand — CAST / TRY_CAST / SAFE_CAST / CONVERT operands are all identifier-shaped (sql/src/main/scala/app/softnetwork/elastic/sql/parser/function/convert/package.scala:28-60), and zero tests exercise a literal operand.

Repro

CAST('125' AS BIGINT)      -- parse error (any statement position)
SELECT CAST('125' AS BIGINT) FROM t   -- parse error
TRY_CAST(1 AS DOUBLE)      -- parse error

Workaround (works today)

The postfix cast operator accepts a literal: '125'::BIGINT (identifierWithValue >> cast, parser/type/package.scala:106). Note :: is always unsafe (CastOperator.safe = false), so there is currently no safe-cast spelling over a bare literal at all — the safe path needs TRY_CAST over a function-of-constants.

Context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions