{"record":{"id":"24f1b4b91774b93a","repo":"hibernate/hibernate-orm","slug":"gaussdb-not-support-datetime-format-yet","errorCode":null,"errorMessage":"GaussDB not support datetime format yet","messagePattern":"GaussDB not support datetime format yet","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/GaussDBDialect.java","lineNumber":960,"sourceCode":"\tpublic boolean supportsJdbcConnectionLobCreation(DatabaseMetaData databaseMetaData) {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean supportsMaterializedLobAccess() {\n\t\t// Prefer using text and bytea over oid (LOB), because oid is very restricted.\n\t\t// If someone really wants a type bigger than 1GB, they should ask for it by using @Lob explicitly\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean supportsTemporalLiteralOffset() {\n\t\treturn true;\n\t}\n\n\t@Override\n\tpublic void appendDatetimeFormat(SqlAppender appender, String format) {\n\t\tthrow new UnsupportedOperationException( \"GaussDB not support datetime format yet\" );\n\t}\n\n\t@Override\n\tpublic String translateExtractField(TemporalUnit unit) {\n\t\treturn switch (unit) {\n\t\t\t//WEEK means the ISO week number\n\t\t\tcase DAY_OF_MONTH -> \"day\";\n\t\t\tcase DAY_OF_YEAR -> \"doy\";\n\t\t\tcase DAY_OF_WEEK -> \"dow\";\n\t\t\tdefault -> super.translateExtractField( unit );\n\t\t};\n\t}\n\n\t@Override\n\tpublic AggregateSupport getAggregateSupport() {\n\t\treturn null;\n\t}\n","sourceCodeStart":942,"sourceCodeEnd":978,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/GaussDBDialect.java#L942-L978","documentation":"GaussDBDialect.appendDatetimeFormat throws UnsupportedOperationException ('GaussDB not support datetime format yet') - the HQL format(datetime as 'pattern') function depends on this hook to rewrite the pattern into database SQL, and the GaussDB dialect has not implemented it, despite inheriting much of PostgreSQLDialect.","triggerScenarios":"Any HQL containing format() - projections like \"select format(t as 'yyyy-MM-dd')\", or predicates like \"where format(t as 'yyyy-MM') = :ym\" - executed while the GaussDB dialect is active. Fails at query translation time, before SQL is issued.","commonSituations":"Applications migrated from PostgreSQL (where format() works via to_char) to GaussDB and assuming full dialect parity; report queries with date labels; Criteria dynamic filtering by formatted periods.","solutions":["Do the formatting in Java with DateTimeFormatter after fetching the raw timestamp","Replace equality-on-format predicates with range predicates on the raw timestamp (start/end of the formatted period) - also index-friendly","Use a native query with GaussDB's to_char if your GaussDB build provides the PostgreSQL-compatible function","Register a custom function through FunctionContributions implementing the pattern until the dialect ships support"],"exampleFix":"// before (HQL, throws on GaussDB)\nsession.createQuery(\"from Reading r where format(r.takenAt as 'yyyy-MM-dd') = :day\", Reading.class)\n    .setParameter(\"day\", \"2026-08-21\")\n\n// after (range predicate on raw timestamp)\nLocalDate day = LocalDate.of(2026, 8, 21);\nsession.createQuery(\"from Reading r where r.takenAt >= :s and r.takenAt < :e\", Reading.class)\n    .setParameter(\"s\", day.atStartOfDay())\n    .setParameter(\"e\", day.plusDays(1).atStartOfDay())","handlingStrategy":"validation","validationCode":"Dialect d = sessionFactory.getJdbcServices().getDialect();\nif (d instanceof GaussDBDialect && hql.contains(\"format(\")) {\n    hql = toRangePredicate(hql); // format(t as 'yyyy-MM-dd') = :d -> t >= :start and t < :end\n}","typeGuard":"static boolean supportsDatetimeFormat(Dialect d) {\n    return !(d instanceof GaussDBDialect);\n}","tryCatchPattern":"try {\n    rows = session.createQuery(hql).list();\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().contains(\"datetime format\")) { /* select raw timestamps, format in Java */ } else throw e;\n}","preventionTips":["Do not assume GaussDB equals PostgreSQL for HQL function coverage - verify dialect features per function","Use range predicates instead of formatted-string comparisons for date filtering","Run shared report queries against GaussDB in CI to catch unimplemented dialect hooks"],"tags":["hibernate","gaussdb","hql","datetime-format","format-function","to-char"],"backgroundTag":"datetime-format-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}