fix(postgres): preserve timezone when editing timestamp precision
Closes #10518
This commit is contained in:
3 files changed
+115
No files matched your search
@@ -1297,11 +1297,32 @@ export function splitDataType(raw: string): { baseType: string; params: string }
|
||||
return { baseType, params };
|
||||
}
|
||||
|
||||
function splitPostgresTemporalDataType(raw: string): { baseType: string; params: string } | null {
|
||||
// format_type() places the precision before the time-zone qualifier. Keep
|
||||
// that qualifier in the base selector so editing only the precision cannot
|
||||
// silently turn timestamptz into timestamp. The anchored built-in names
|
||||
// deliberately exclude domains and schema-qualified custom types.
|
||||
const match = raw.trim().match(/^(TIME|TIMESTAMP|TIMETZ|TIMESTAMPTZ)\s*\(([^()]*)\)(?:\s+((?:WITH|WITHOUT)\s+TIME\s+ZONE))?((?:\s*\[\])*)$/i);
|
||||
if (!match) return null;
|
||||
const typeName = match[1]!;
|
||||
const qualifier = match[3]?.replace(/\s+/g, " ");
|
||||
if (qualifier && !/^(?:TIME|TIMESTAMP)$/i.test(typeName)) return null;
|
||||
const arraySuffix = (match[4] ?? "").replace(/\s+/g, "");
|
||||
return {
|
||||
baseType: `${typeName}${qualifier ? ` ${qualifier}` : ""}${arraySuffix}`,
|
||||
params: match[2]!.trim(),
|
||||
};
|
||||
}
|
||||
|
||||
function splitDataTypeForDatabase(dbType: DatabaseType | undefined, raw: string): { baseType: string; params: string } {
|
||||
if (dbType === "duckdb") {
|
||||
const parsed = splitDuckdbScalarDataType(raw);
|
||||
if (parsed) return parsed;
|
||||
}
|
||||
if (dbType === "postgres") {
|
||||
const parsed = splitPostgresTemporalDataType(raw);
|
||||
if (parsed) return parsed;
|
||||
}
|
||||
if (dbType === "xugu") {
|
||||
const match = raw.trim().match(/^(TIME|TIMESTAMP)\s*\(([^()]*)\)\s+WITH\s+TIME\s+ZONE$/i);
|
||||
if (match) {
|
||||
@@ -1466,6 +1487,10 @@ function combineQualifiedTemporalType(baseType: string, params: string, dbType:
|
||||
const match = baseType.trim().match(/^(TIMESTAMP)\s+WITHOUT\s+TIME\s+ZONE$/i);
|
||||
return match ? (params ? `${match[1]}(${params}) WITHOUT TIME ZONE` : baseType.trim()) : null;
|
||||
}
|
||||
if (dbType === "postgres") {
|
||||
const match = baseType.trim().match(/^(TIME|TIMESTAMP)\s+((?:WITH|WITHOUT)\s+TIME\s+ZONE)$/i);
|
||||
return match ? (params ? `${match[1]}(${params}) ${match[2]!.replace(/\s+/g, " ")}` : baseType.trim()) : null;
|
||||
}
|
||||
if (dbType !== "xugu") return null;
|
||||
const match = baseType.trim().match(/^(TIME|TIMESTAMP)\s+WITH\s+TIME\s+ZONE$/i);
|
||||
if (!match) return null;
|
||||
|
||||
Reference in new issue
Block a user