kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.44k stars 267 forks source link

<statement expected> got .... instead when using sql function #1066

Closed Mathieu-R closed 3 months ago

Mathieu-R commented 3 months ago

Hi !

Using Kysely 0.27.3 , I have the following error when using the sql function:

<statement expected> got .... instead

with ... is the string I pass between the backticks to the sql function.

For example, running a migration and trying to set a default value for a created_at column:

await db.schema
    .createTable('users')
    // other columns definition
    // ...
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
    .execute()

The error is then <statement expected> got 'CURRENT_TIMESTAMP' instead.

Note that despite my editor crying this error, the migration is still running correctly though.