diff --git a/apps/desktop/src/lib/table/tableStructureEditorState.ts b/apps/desktop/src/lib/table/tableStructureEditorState.ts index 36b348f43c..fb0af64801 100644 --- a/apps/desktop/src/lib/table/tableStructureEditorState.ts +++ b/apps/desktop/src/lib/table/tableStructureEditorState.ts @@ -5,6 +5,12 @@ export function hasExistingColumnTypeChange(columns: readonly EditableStructureC return columns.some((column) => !!column.original && !column.markedForDrop && column.dataType !== column.original.data_type); } +const POSTGRES_SERIAL_PSEUDO_TYPES = new Set(["smallserial", "serial", "bigserial"]); + +function withPostgresArrayTypes(types: readonly string[]): string[] { + return [...types, ...types.filter((type) => !POSTGRES_SERIAL_PSEUDO_TYPES.has(type)).map((type) => `${type}[]`)]; +} + export const DATA_TYPE_OPTIONS: Record = { mysql: [ "tinyint", @@ -58,7 +64,7 @@ export const DATA_TYPE_OPTIONS: Record = { "multipolygon", "geometrycollection", ], - postgres: [ + postgres: withPostgresArrayTypes([ "smallint", "int2", "integer", @@ -122,7 +128,7 @@ export const DATA_TYPE_OPTIONS: Record = { "tstzrange", "daterange", "oid", - ], + ]), sqlite: ["integer", "real", "text", "blob", "numeric"], rqlite: ["integer", "real", "text", "blob", "numeric"], turso: ["integer", "real", "text", "blob", "numeric"], @@ -1161,7 +1167,7 @@ export function isDataTypeLengthDisabled(_dbType: DatabaseType | undefined, base } else if (_dbType === "manticoresearch") { return key !== "bit" && key !== "float_vector"; } else if (_dbType === "postgres" || _dbType === "gaussdb" || _dbType === "kwdb" || _dbType === "opengauss" || _dbType === "highgo" || _dbType === "uxdb" || _dbType === "vastbase" || _dbType === "kingbase") { - return POSTGRES_TYPE_LENGTH_DISABLES.includes(key); + return key.endsWith("[]") || POSTGRES_TYPE_LENGTH_DISABLES.includes(key); } else if (isOracleLikeStructureType(_dbType)) { // Dameng/Oracle integer aliases have fixed precision; MySQL-style display widths generate invalid DDL. return ORACLE_LIKE_TYPE_LENGTH_DISABLES.includes(key); diff --git a/packages/app-tests/tableStructureEditorState.test.ts b/packages/app-tests/tableStructureEditorState.test.ts index 8e7983d653..5c755569a9 100644 --- a/packages/app-tests/tableStructureEditorState.test.ts +++ b/packages/app-tests/tableStructureEditorState.test.ts @@ -14,6 +14,7 @@ import { generateUniqueIndexName, getColumnEditorControls, getDataTypeOptions, + isDataTypeLengthDisabled, isProtectedManticoreIdColumn, isDamengIdentityCompatibleDataType, isMysqlEnumDataType, @@ -485,6 +486,21 @@ test("returns data type options for compatible table structure editors", () => { assert.equal(getDataTypeOptions("sqlserver").includes("nvarchar"), true); }); +test("returns PostgreSQL array type options without serial pseudo-types", () => { + const options = getDataTypeOptions("postgres"); + assert.equal(options.includes("integer[]"), true); + assert.equal(options.includes("character varying[]"), true); + assert.equal(options.includes("jsonb[]"), true); + assert.equal(options.includes("serial[]"), false); + assert.equal(options.includes("smallserial[]"), false); + assert.equal(options.includes("bigserial[]"), false); +}); + +test("does not append length parameters after PostgreSQL array brackets", () => { + assert.equal(isDataTypeLengthDisabled("postgres", "varchar[]"), true); + assert.equal(combineDataTypeForDatabase("postgres", "varchar[]", "20"), "varchar[]"); +}); + test("returns Xugu data type options", () => { const options = getDataTypeOptions("xugu"); assert.equal(options.includes("INTEGER"), true);