@@ -21,11 +21,12 @@ description: "SqlDialect, SqlResult, AbstractSqlDialect, and the dialect matrix"
2121parameterized ` SqlResult ` . Three built-in dialects are provided as constants
2222on the interface:
2323
24- | Constant | Identifier quoting | DELETE LIMIT |
25- | ----------| --------------------| --------------|
26- | ` SqlDialect.STANDARD ` | None (ANSI) | Not supported |
27- | ` SqlDialect.MYSQL ` | Back-tick `` ` `` | Supported |
28- | ` SqlDialect.SQLITE ` | Double-quote ` " ` | Supported |
24+ | Constant | Identifier quoting | DELETE LIMIT | ILIKE | RETURNING |
25+ | ----------| --------------------| --------------| ------| ----------|
26+ | ` SqlDialect.STANDARD ` | None (ANSI) | Not supported | No | No |
27+ | ` SqlDialect.MYSQL ` | Back-tick `` ` `` | Supported | No | No |
28+ | ` SqlDialect.SQLITE ` | Double-quote ` " ` | Supported | No | No |
29+ | ` SqlDialect.POSTGRESQL ` | Double-quote ` " ` | Not supported | Yes | Yes (DELETE) |
2930
3031---
3132
@@ -54,6 +55,14 @@ SqlResult r3 = new QueryBuilder()
5455 .whereEquals(" id" , 1 )
5556 .buildSql(SqlDialect . SQLITE );
5657// → SELECT * FROM "users" WHERE "id" = ?
58+
59+ // PostgreSQL: double-quoted identifiers + ILIKE support
60+ SqlResult r4 = new QueryBuilder ()
61+ .from(" users" )
62+ .whereILike(" email" , " alice" )
63+ .buildSql(SqlDialect . POSTGRESQL );
64+ // → SELECT * FROM "users" WHERE "email" ILIKE ?
65+ // Parameters: ["%alice%"]
5766```
5867
5968---
@@ -87,7 +96,8 @@ List<Object> params = result.getParameters();
8796## Rendering DELETE statements
8897
8998Use ` renderDelete(Query) ` on a dialect instance to produce ` DELETE FROM ... `
90- statements. This respects the ` LIMIT ` clause on dialects that support it.
99+ statements. This respects the ` LIMIT ` clause on dialects that support it and
100+ the ` RETURNING ` clause on PostgreSQL.
91101
92102``` java
93103Query q = new QueryBuilder ()
@@ -109,25 +119,30 @@ SqlResult sq = SqlDialect.SQLITE.renderDelete(q);
109119// → DELETE FROM "sessions" WHERE "expired" = ? LIMIT 500
110120```
111121
122+ For PostgreSQL ` RETURNING ` , use ` DeleteBuilder.returning() ` — see [ DML Builders] ( dml-builders#returning-clause-postgresql ) .
123+
112124---
113125
114126## Dialect matrix
115127
116128The same ` Query ` produces different SQL across dialects due to identifier quoting:
117129
118- | Feature | STANDARD | MYSQL | SQLITE |
119- | ---------| ----------| -------| --------|
120- | Table quoting | ` users ` | `` `users` `` | ` "users" ` |
121- | Column quoting | ` id ` | `` `id` `` | ` "id" ` |
122- | DELETE LIMIT | No | Yes | Yes |
123- | Parameter syntax | ` ? ` | ` ? ` | ` ? ` |
130+ | Feature | STANDARD | MYSQL | SQLITE | POSTGRESQL |
131+ | ---------| ----------| -------| --------| ------------|
132+ | Table quoting | ` users ` | `` `users` `` | ` "users" ` | ` "users" ` |
133+ | Column quoting | ` id ` | `` `id` `` | ` "id" ` | ` "id" ` |
134+ | DELETE LIMIT | No | Yes | Yes | No |
135+ | ILIKE / NOT ILIKE | No | No | No | Yes |
136+ | RETURNING on DELETE | No | No | No | Yes |
137+ | Parameter syntax | ` ? ` | ` ? ` | ` ? ` | ` ? ` |
124138
125139---
126140
127141## AbstractSqlDialect
128142
129143` AbstractSqlDialect ` implements the shared rendering logic for SELECT and DELETE
130- queries. It is the base class for both ` MySqlDialect ` and ` SqliteDialect ` .
144+ queries. It is the base class for ` MySqlDialect ` , ` SqliteDialect ` , and
145+ ` PostgreSqlDialect ` .
131146
132147** Subquery parameter ordering** : parameters are collected depth-first in this
133148order:
@@ -137,17 +152,9 @@ order:
1371523 . JOIN subquery parameters (left to right)
1381534 . WHERE condition subquery parameters (top to bottom)
139154
140- To create a custom dialect (e.g. PostgreSQL with ` "..." ` quoting), extend
141- ` AbstractSqlDialect ` and override ` quoteIdentifier ` :
142-
143- ``` java
144- public class PostgreSqlDialect extends AbstractSqlDialect {
145- @Override
146- protected String quoteIdentifier (String name ) {
147- return ' "' + name + ' "' ;
148- }
149- }
150- ```
155+ To create a fully custom dialect, extend ` AbstractSqlDialect ` and override any
156+ combination of ` quoteIdentifier ` , ` supportsDeleteLimit ` , ` supportsReturning ` ,
157+ and ` appendConditionFragment ` .
151158
152159---
153160
@@ -158,5 +165,6 @@ public class PostgreSqlDialect extends AbstractSqlDialect {
158165| ` SqlDialect.STANDARD ` | ANSI SQL constant instance |
159166| ` SqlDialect.MYSQL ` | MySQL dialect constant instance |
160167| ` SqlDialect.SQLITE ` | SQLite dialect constant instance |
168+ | ` SqlDialect.POSTGRESQL ` | PostgreSQL dialect constant instance |
161169| ` render(Query) ` | Render a ` SELECT ` query to ` SqlResult ` |
162- | ` renderDelete(Query) ` | Render a ` DELETE ` query to ` SqlResult ` ; observes ` LIMIT ` on supporting dialects |
170+ | ` renderDelete(Query) ` | Render a ` DELETE ` query to ` SqlResult ` ; observes ` LIMIT ` and ` RETURNING ` on supporting dialects |
0 commit comments