Craticula

Dialects and providers

This page lists the databases Craticula can write queries for, how their queries differ, and which versions are tested. It is for a developer who is choosing a database or a dialect, or who wants to know why the same request gives different text on each.

What a dialect is #

The same request means the same thing on every backend. Craticula decides what it means once, in the canonical form. Then one writer per database spells it in that database's language.

For SQL, that writer is a dialect. A dialect class has a single shared Instance, such as PostgresDialect.Instance. You pass it to SqlQueryBuilder.Build. There are five:

DatabaseDialect class
PostgreSQLPostgresDialect
SQL ServerMssqlDialect
MySQL (MariaDB goes through the same dialect but has never been tested)MySqlDialect
SQLiteSqliteDialect
OracleOracleDialect

MongoDB and OpenSearch have their own compilers, MongoPipelineBuilder and SearchQueryBuilder. They do not take a dialect. See MongoDB and OpenSearch adapters.

How the SQL differs #

DatabasePlaceholderQuotingPaging
PostgreSQL$1, $2"name"LIMIT and OFFSET
SQL Server@p1, @p2[name]OFFSET ... ROWS FETCH NEXT ... ROWS ONLY
MySQL?`name`LIMIT and OFFSET
SQLite?"name"LIMIT and OFFSET
Oracle:p1, :p2"name"OFFSET ... ROWS FETCH NEXT ... ROWS ONLY

In every case the values are parameters, listed in the order the placeholders appear. Every table and column name is quoted, and a quote character inside a name is doubled. See The safety model.

PostgreSQL passes an "in" list as one array parameter. The other databases write one placeholder for each value.

Null ordering #

Craticula states where nulls sort in every query, so the order does not depend on the database's default. The way it says so depends on the database:

See Paging and sorting.

Case-insensitive comparison #

A text field compares without regard to case unless the schema says otherwise. Each database gets there differently:

DatabaseHow it ignores case
PostgreSQLCOLLATE craticula_ci on comparisons and sorts, which you create once. ILIKE for contains, startsWith and endsWith.
SQL ServerCOLLATE Latin1_General_CI_AS in the query. A case-sensitive field gets Latin1_General_CS_AS.
MySQLNothing in the query. The column's own collation decides. A case-sensitive field needs a _bin or _as_cs column.
SQLiteCOLLATE NOCASE, which folds ASCII letters only.
OracleCOLLATE BINARY_CI. A case-sensitive field gets COLLATE BINARY.
MongoDBA collation on the whole query, with locale en and strength 2.
OpenSearch and ElasticsearchThe case_insensitive option on term and wildcard queries, and a normalized sub-field for sorting and ranges.

Two cases are silent: a case-sensitive field on MySQL, and the grouping columns on SQL Server, MySQL and Oracle. The statement runs and returns wrong rows if the column's collation is not the one Craticula assumes. Index and database guidance lists what to set for each: Index and database guidance.

Versions #

These are the lowest versions the compiled queries need, taken from the specification and the vendors' documentation, not from a test run. Only the tested column was run. The Elasticsearch adapter is documented for 8.x.

DatabaseMinimumWhat the tests ran against
PostgreSQL12, with ICU16
SQL Servernone stated2022
MySQLnone stated8.4
SQLite3.30.0not recorded
Oracle12.2Database Free 23ai
MongoDB4.27.0
OpenSearch1.02.19
Elasticsearch7.108.17

"None stated" means the code and the specification set no floor, not that every old release has been tried. MariaDB uses the MySQL dialect, but no test runs on MariaDB.

The tests run the compiled queries against real databases in containers. That run needs Docker and is not part of the quick test run, so check the repository for the latest state.

Oracle's status #

Oracle is supported as a community-tested dialect, not as a v1 core dialect. It is graded the same way as the others: every statement is compared with a stored expected text. The difference is coverage. It is checked against a smaller set of examples than the other four, 45 in all. Those 45 also run against a real Oracle Database Free 23ai server.

Oracle 12.2 to 21c have not been run. The 12.2 minimum comes from Oracle's documentation, not from a measurement.

Three Oracle facts shape the output:

Providers #

A provider here means the library that actually talks to the database. Craticula does not choose one for you.

The repository has a demo app in examples/demo that you run yourself. It reads the same synthetic orders from several of these databases and compares the answers.

Where this comes from #