Bug fix: "Create Table" script generation dropped "with time zone" from TIMESTAMP/TIME column - #98
Open
nrworld wants to merge 1 commit into
Open
Conversation
… TIMESTAMP/TIME columns. java.sql.Types.TIMESTAMP/TIME don't distinguish plain and "with time zone" variants, so every dialect's hard-coded type registry mapped both to the same bare "timestamp"/"time" name, discarding the qualifier even though the driver's real TYPE_NAME (e.g. PostgreSQL's timestamptz/timetz) carried it. Fixed once in CommonHibernateDialect.getTypeName(TableColumnInfo), the shared chokepoint used by every dialect's create-table and alter-column-type SQL generation, so all dialects pick up the fix without per-dialect changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When generating a "Create Table" DDL script for an existing table (right-click table → Scripts → Create), SQuirreL emitted timestamp instead of timestamp with time zone for PostgreSQL
columns that actually have a timezone (timestamptz). The same applied to time/timetz.
Root cause
java.sql.Types.TIMESTAMP and Types.TIME don't distinguish the plain and "with time zone" variants. Every dialect registers a flat mapping (e.g. PostgreSQLDialectExt:
registerColumnType(Types.TIMESTAMP, "timestamp")), so the qualifier is silently dropped — even though it is present in the driver's real JDBC TYPE_NAME (e.g. Postgres reports
timestamptz/timetz).
Fix
Added one shared post-processing step in CommonHibernateDialect.getTypeName(TableColumnInfo) — the single chokepoint used by every dialect for both "Create Table" and "Alter Column Type"
DDL generation. After resolving the base type name, it checks the driver's raw TYPE_NAME for a timezone indicator (timestamptz, timetz, or a "with time zone" substring) and appends " with
time zone" if the resolved name doesn't already have it.
This is a shared fix rather than a Postgres-only patch, so it also covers other ANSI-timezone-capable dialects (H2, HSQLDB, Derby, Firebird, etc.) that inherit getTypeName(TableColumnInfo)
from CommonHibernateDialect without requiring any per-dialect changes.
File changed: sql12/core/src/net/sourceforge/squirrel_sql/fw/dialects/CommonHibernateDialect.java (+41/-1)
Testing
Note: Used Sonnet 5 for development of the fix