SQL statements in lowercase provided confusing error messages
See original GitHub issueSQLDelight 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:
- Created a year ago
- Reactions:3
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Here is a twitter poll about SQL casing from Lukas Eder, the creator of jOOQ, just for context. https://twitter.com/lukaseder/status/1052809813447593986