Skip to content

Generated hash aliases starting with digits cause SQL syntax errors in raw queries #11657

@LeviHeber

Description

@LeviHeber

Issue description

When TypeORM generates hash-based aliases, the resulting alias can start with a digit (0-9). This creates invalid SQL identifiers that cause syntax errors when used in raw queries.

Expected Behavior

Generated aliases should always start with a letter to create valid SQL identifiers that can be safely used in all SQL contexts.

Actual Behavior

raw queries fail with SQL syntax errors when auto-generated aliases start with digits:
QueryFailedError: trailing junk after numeric literal at or near "[alias_starting_with_digit]"

Steps to reproduce

  1. Use nested relations that generate long internal aliases
  2. Apply a Raw() filter that references the generated alias
  3. Error occurs when the generated hash starts with a digit

My Environment

Dependency Version
Operating System Windows
Node.js version v20.10.0
Typescript version 5.8.3
TypeORM version 0.3.26

Additional Context

This issue occurs with nested relations where TypeORM internally generates aliases for deep object property paths. The problem is deterministic - certain relation paths will consistently generate problematic aliases while others work fine.

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions