{"id":"93aa318e7402c531","repo":"drizzle-team/drizzle-orm","slug":"unsupported-geometry-type","errorCode":null,"errorMessage":"Unsupported geometry type","messagePattern":"Unsupported geometry type","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/pg-core/columns/postgis_extension/utils.ts","lineNumber":46,"sourceCode":"\tconst geomType = view.getUint32(offset, byteOrder === 1);\n\toffset += 4;\n\n\tlet _srid: number | undefined;\n\tif (geomType & 0x20000000) { // SRID flag\n\t\t_srid = view.getUint32(offset, byteOrder === 1);\n\t\toffset += 4;\n\t}\n\n\tif ((geomType & 0xFFFF) === 1) {\n\t\tconst x = bytesToFloat64(bytes, offset);\n\t\toffset += 8;\n\t\tconst y = bytesToFloat64(bytes, offset);\n\t\toffset += 8;\n\n\t\treturn [x, y];\n\t}\n\n\tthrow new Error('Unsupported geometry type');\n}\n","sourceCodeStart":28,"sourceCodeEnd":48,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/pg-core/columns/postgis_extension/utils.ts#L28-L48","documentation":"An Error 'Unsupported geometry type' thrown by parseEWKB() in drizzle-orm/src/pg-core/columns/postgis_extension/utils.ts:46. The parser decodes PostGIS EWKB but currently handles only the Point geometry (geomType & 0xFFFF === 1). After skipping the optional SRID, any non-Point geometry (LineString=2, Polygon=3, MultiPoint=4, etc.) falls through to this throw.","triggerScenarios":"Decoding a PostGIS column whose stored value is anything other than a Point (e.g. LineString, Polygon, MultiPolygon, GeometryCollection) using a column that calls parseEWKB on its EWKB hex. Selecting such a row triggers the throw at read time.","commonSituations":"Storing routes (LineString), areas (Polygon), or multi-geometries in a PostGIS column and reading them back through Drizzle's postgis helpers, which currently only round-trip Points. A schema change that starts storing non-Point geometries breaks previously working reads.","solutions":["If you only need coordinates, store Points instead of higher-dimensional geometries.","Otherwise do not decode with parseEWKB — read the column as raw text/bytea and decode with a full EWKB library (e.g. wkx/@turf) client-side.","Request/await broader geometry support in drizzle-orm if you need native decoding.","Filter or transform non-Point rows before they reach the Drizzle decoder."],"exampleFix":"// before — column of LineStrings decoded via the Point-only parser\nconst routes = pgTable('routes', {\n  id: serial('id').primaryKey(),\n  geom: geometry('geom', { type: 'linestring', srid: 4326 }),\n});\nawait db.select().from(routes); // Unsupported geometry type\n\n// after — read raw EWKB hex and decode with a full library\nconst routes = pgTable('routes', {\n  id: serial('id').primaryKey(),\n  geom: text('geom').notNull(), // or customType returning raw\n});\nconst rows = await db.select().from(routes);\nconst geo = rows.map(r => parseWKH(r.geom)); // use wkx / @turf to parse linestring","handlingStrategy":"type-guard","validationCode":"function isPointEWKB(hex: string): boolean {\n  // EWKB: 1 byte order + 4 bytes geomType (+ optional SRID). Point type low bits === 1.\n  const bytes = new Uint8Array(\n    hex.match(/.{2}/g)!.map((h) => parseInt(h, 16)),\n  );\n  const little = bytes[0] === 1;\n  const view = new DataView(bytes.buffer);\n  const geomType = view.getUint32(1, little);\n  return (geomType & 0xffff) === 1;\n}\n\nif (!isPointEWKB(hexValue)) {\n  // do not pass to parseEWKB; decode with a full EWKB library instead\n}","typeGuard":"function isPointGeometry(hex: string): boolean {\n  if (!hex || hex.length < 10) return false;\n  const bytes = new Uint8Array(hex.match(/.{2}/g)!.map((h) => parseInt(h, 16)));\n  const little = bytes[0] === 1;\n  const geomType = new DataView(bytes.buffer).getUint32(1, little);\n  return (geomType & 0xffff) === 1;\n}","tryCatchPattern":"try {\n  const [x, y] = parseEWKB(hexValue);\n} catch (e) {\n  if (e instanceof Error && /Unsupported geometry type/i.test(e.message)) {\n    // fall back to a full EWKB decoder (wkx/@turf) for non-Point geometries\n  } else throw e;\n}","preventionTips":["Only use parseEWKB-backed columns for Point geometries.","For LineString/Polygon/Multi*, read raw EWKB and decode with a full geometry library client-side.","Add a column type check or unit test asserting stored geometries are Points."],"tags":["postgres","postgis","geometry","ewkb","decode"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}