Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

use opinionated standard sql dialect (#6128)

Shahmir Varqha9259ecdd41bb
diff --git a/frontend/src/core/codemirror/language/languages/sql/completion-store.ts b/frontend/src/core/codemirror/language/languages/sql/completion-store.ts
index 719bf733b9..80d8424db1 100644
--- a/frontend/src/core/codemirror/language/languages/sql/completion-store.ts
+++ b/frontend/src/core/codemirror/language/languages/sql/completion-store.ts
@@ -1,10 +1,6 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import {
- type SQLConfig,
- type SQLDialect,
- StandardSQL,
-} from "@codemirror/lang-sql";
+import type { SQLConfig, SQLDialect } from "@codemirror/lang-sql";
import { isSchemaless } from "@/components/datasources/utils";
import { dataConnectionsMapAtom } from "@/core/datasets/data-source-connections";
import type { ConnectionName } from "@/core/datasets/engines";
@@ -12,7 +8,7 @@ import { datasetTablesAtom } from "@/core/datasets/state";
import type { DataSourceConnection } from "@/core/kernel/messages";
import { store } from "@/core/state/jotai";
import { LRUCache } from "@/utils/lru";
-import { guessDialect } from "./utils";
+import { guessDialect, ModifiedStandardSQL } from "./utils";
type TableToCols = Record<string, string[]>;
type Schemas = Record<string, TableToCols>;
@@ -134,9 +130,9 @@ class SQLCompletionStore {
getDialect(connectionName: ConnectionName): SQLDialect {
const connection = this.getConnection(connectionName);
if (!connection) {
- return StandardSQL;
+ return ModifiedStandardSQL;
}
- return guessDialect(connection) ?? StandardSQL;
+ return guessDialect(connection) ?? ModifiedStandardSQL;
}
getCompletionSource(connectionName: ConnectionName): SQLConfig | null {
@@ -160,7 +156,7 @@ class SQLCompletionStore {
const schema = this.cache.getOrCreate(connection);
return {
- dialect: guessDialect(connection),
+ dialect: guessDialect(connection) ?? ModifiedStandardSQL,
schema: schema.shouldAddLocalTables
? { ...schema.schema, ...getTablesMap() }
: schema.schema,
diff --git a/frontend/src/core/codemirror/language/languages/sql/utils.ts b/frontend/src/core/codemirror/language/languages/sql/utils.ts
index 35f16ed512..65457e4fae 100644
--- a/frontend/src/core/codemirror/language/languages/sql/utils.ts
+++ b/frontend/src/core/codemirror/language/languages/sql/utils.ts
@@ -1,6 +1,5 @@
/* Copyright 2024 Marimo. All rights reserved. */
-import type { SQLDialect } from "@codemirror/lang-sql";
import {
Cassandra,
MariaSQL,
@@ -8,7 +7,10 @@ import {
MySQL,
PLSQL,
PostgreSQL,
+ SQLDialect,
+ type SQLDialectSpec,
SQLite,
+ StandardSQL,
} from "@codemirror/lang-sql";
import { DuckDBDialect } from "@marimo-team/codemirror-sql/dialects";
import type { DataSourceConnection } from "@/core/kernel/messages";
@@ -40,3 +42,13 @@ export function guessDialect(
return undefined;
}
}
+
+const OpinionatedStandardSQL: SQLDialectSpec = {
+ ...StandardSQL,
+ // Upper-case identifiers do not need to be quoted most of the time
+ caseInsensitiveIdentifiers: true,
+ // Encase identifiers in single quotes instead of \
+ identifierQuotes: "'",
+};
+
+export const ModifiedStandardSQL = SQLDialect.define(OpinionatedStandardSQL);