question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQL statements in lowercase provided confusing error messages

See original GitHub issue

SQLDelight Version

1.5.3

SQLDelight Dialect

mysql

Describe the Bug

I was migrating an existing project to use SQLDelight. I had the following in the first migration schema file:

create table foo (
`id` bigint primary key not null auto_increment,
`created_at` timestamp not null default current_timestamp on update current_timestamp,
`name` varchar(32) not null unique,
key `index_on_name` (`name`)
) engine=InnoDB default charset=utf8mb4;

and I got a ream of error messages, the first of which was this:

/path/to/migration.sqm line 1:7 - '{' expected, got 'table'
1    table
            ^^^^^

It took a couple of minutes to figure out why this was failing since the error message wasn’t too helpful but the problem turned out to be case-sensitivity. Although the SQL statement as written works fine in a MySQL 5.7 database, it needs to be converted to uppercase for SQLDelight to recognize it:

CREATE TABLE foo (
`id` bigint PRIMARY KEY NOT NULL AUTO_INCREMENT,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`name` varchar(32) NOT NULL UNIQUE,
KEY `index_on_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

It would be great if the SQL parsing engine in SQLDelight could detect this (probably frequent) error and emit a more useful error message. Or even better, just accept the lowercase SQL.

Stacktrace

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

1reaction
alllexcommented, Jul 7, 2022

I was also very surprised by this behavior. SQL as a language is case-insensitive with regard to keywords and should be supported as such.

I got this error for SQLite dialect, but I suspect it is the same for all dialects.

0reactions
morkicommented, Oct 21, 2022

Here is a twitter poll about SQL casing from Lukas Eder, the creator of jOOQ, just for context. https://twitter.com/lukaseder/status/1052809813447593986

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why should I capitalize my SQL keywords? Is there a good ...
Code has punctuation which SQL statements lack. There are dots and parentheses and semicolons to help you keep things separate.
Read more >
54.3. Error Message Style Guide - Postgres-XL
Lower Case. Use lower case for message wording, including the first letter of a primary error message. Use upper case for SQL commands...
Read more >
Is SQL Case-Sensitive? - LearnSQL.com
In MS SQL Server, the most common practice is to use PascalCase. Differences in case sensitivity can lead to problems in executing your...
Read more >
Rules Reference — SQLFluff 1.4.4 documentation
Rules in SQLFluff are implemented as crawlers . These are entities which work their way through the parsed structure of a query to...
Read more >
Collation and Unicode support - SQL Server - Microsoft Learn
Learn about collation and Unicode support in SQL Server.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found