Class PostgresDialect
- All Implemented Interfaces:
SqlDialect
SqlDialect: the one dialect Juneau ships for the shared JDBC SqlBeanQueryContext.
It renders the built-in $-operators (design §5.1) into Postgres predicates that mirror the in-memory
semantics: exact, case-sensitive $eq/$in/$ne on text/id/enum columns, with the
case-insensitive $eqic (and the case-insensitive $contains/$prefix) via lower(...)
and ILIKE; full-string $regex via ~/~* with the same i/m/s
flag semantics as java.util.regex; dotted-tuple version comparison and $prefix; and typed binds for
numeric/boolean/timestamp comparisons. A bare pattern maps * to % and ? to _ for
ILIKE, unless the literal was quoted in the search string, in which case it is matched literally.
Values arrive already typed (design #4 §4: SearchType.parse(String) runs during query resolution, before
this dialect ever sees a value), and are always bound as ? parameters, never concatenated into SQL text.
- ENUM columns are compared as text: the column is cast (
col::text) wherever this dialect applies a text function or operator to it, so a native Postgresenumcolumn behaves like atextone (including bare*/?wildcards, which match the whole constant name, case-insensitively). - VERSION columns are stored as dotted text (for example
10.0.1) and compared as a tuple of integers (10.9sorts before10.10), like the in-memory engine. A stored value that is not a dotted sequence of integers never matches. Known, deliberate differences from the in-memory parser (Integer.parseIntoversplit("\\.")): each part is limited to 9 digits here (so it always fits a Postgresint; longer parts never match, where in-memory accepts up to theintrange), and a trailing empty part (10.) or a signed part (+1,-1) is rejected here but accepted in-memory. - Blank (
$blank, and the blank-matching$ne) meansNULLor only ASCII whitespace (space, tab, line breaks, vertical tab, form feed and the C0 separators), matchingString.isBlank()for ASCII; non-ASCII Unicode spaces are not trimmed.
Example:
- Since:
- 10.0.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbuiltinRenderer(String operatorName) The renderer for a built-in leaf operator (for example"$eq"), ornull if this dialect cannot express it.id()The stable lowercase dialect id (for example"postgres").Quotes a column or table identifier for this dialect (for exampleage→"age").renderBare(String columnSql, SearchType type, Object value, boolean quoted) Renders a bare pattern term (design §5.1) — text with optional*/?wildcards, a version prefix, or an exact value for the other types — into a predicate.renderLimitOffset(Long limit, Long offset) Renders the pagination clause appended to aSELECT(for example" LIMIT 10 OFFSET 20").booleanPostgres compares versions asint[]tuples (seeversionArray(java.lang.String)), matching the in-memory order.
-
Field Details
-
INSTANCE
The singleton instance.
-
-
Method Details
-
id
Description copied from interface:SqlDialectThe stable lowercase dialect id (for example"postgres").- Specified by:
idin interfaceSqlDialect- Returns:
- The dialect id, never
null or blank.
-
supportsVersionOrdering
Postgres compares versions asint[]tuples (seeversionArray(java.lang.String)), matching the in-memory order.- Specified by:
supportsVersionOrderingin interfaceSqlDialect- Returns:
true if version range comparisons match the in-memory semantics.
-
quote
Description copied from interface:SqlDialectQuotes a column or table identifier for this dialect (for exampleage→"age").- Specified by:
quotein interfaceSqlDialect- Parameters:
identifier- The raw identifier. Must not benull .- Returns:
- The quoted identifier.
-
builtinRenderer
Description copied from interface:SqlDialectThe renderer for a built-in leaf operator (for example"$eq"), ornull if this dialect cannot express it.The context calls this only for built-in leaves; it handles the
$and/$or/$notcombinators itself. Anull return makes the context fail with a clear error rather than emit wrong SQL.- Specified by:
builtinRendererin interfaceSqlDialect- Parameters:
operatorName- The built-in operator name, including the leading$. Must not benull .- Returns:
- The renderer, or
null if unsupported.
-
renderLimitOffset
Description copied from interface:SqlDialectRenders the pagination clause appended to aSELECT(for example" LIMIT 10 OFFSET 20").The limit/offset are inlined as integer literals (never bind values), so the returned text carries no placeholders.
- Specified by:
renderLimitOffsetin interfaceSqlDialect- Parameters:
limit- The maximum row count, ornull for no limit.offset- The zero-based start offset, ornull /0for none.- Returns:
- The pagination clause (possibly empty, never
null ).
-
renderBare
Description copied from interface:SqlDialectRenders a bare pattern term (design §5.1) — text with optional*/?wildcards, a version prefix, or an exact value for the other types — into a predicate.- Specified by:
renderBarein interfaceSqlDialect- Parameters:
columnSql- The dialect-quoted column reference. Must not benull .type- The column's value type. Must not benull .value- The literal's already-typed value (SearchExpression.typedValue()): aBigDecimalforNUMERIC, aBooleanforBOOLEAN, anOffsetDateTime,LocalDateTimeorLocalDateforTIMESTAMP, and the already-$$-decodedStringforTEXT,ID,ENUMandVERSION. Must not benull .quoted- Whether the literal was quoted in the search string; a quoted literal is never given wildcard interpretation, even if it contains*or?.- Returns:
- The predicate fragment.
-