drizzle-team/drizzle-orm · error · Error
Unsupported geometry type
Error message
Unsupported geometry type
What it means
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.
Source
Thrown at drizzle-orm/src/pg-core/columns/postgis_extension/utils.ts:46
const geomType = view.getUint32(offset, byteOrder === 1);
offset += 4;
let _srid: number | undefined;
if (geomType & 0x20000000) { // SRID flag
_srid = view.getUint32(offset, byteOrder === 1);
offset += 4;
}
if ((geomType & 0xFFFF) === 1) {
const x = bytesToFloat64(bytes, offset);
offset += 8;
const y = bytesToFloat64(bytes, offset);
offset += 8;
return [x, y];
}
throw new Error('Unsupported geometry type');
}
View on GitHub (pinned to b7862528fd)
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.
Example fix
// before — column of LineStrings decoded via the Point-only parser
const routes = pgTable('routes', {
id: serial('id').primaryKey(),
geom: geometry('geom', { type: 'linestring', srid: 4326 }),
});
await db.select().from(routes); // Unsupported geometry type
// after — read raw EWKB hex and decode with a full library
const routes = pgTable('routes', {
id: serial('id').primaryKey(),
geom: text('geom').notNull(), // or customType returning raw
});
const rows = await db.select().from(routes);
const geo = rows.map(r => parseWKH(r.geom)); // use wkx / @turf to parse linestring Defensive patterns
Strategy: type-guard
Validate before calling
function isPointEWKB(hex: string): boolean {
// EWKB: 1 byte order + 4 bytes geomType (+ optional SRID). Point type low bits === 1.
const bytes = new Uint8Array(
hex.match(/.{2}/g)!.map((h) => parseInt(h, 16)),
);
const little = bytes[0] === 1;
const view = new DataView(bytes.buffer);
const geomType = view.getUint32(1, little);
return (geomType & 0xffff) === 1;
}
if (!isPointEWKB(hexValue)) {
// do not pass to parseEWKB; decode with a full EWKB library instead
} Type guard
function isPointGeometry(hex: string): boolean {
if (!hex || hex.length < 10) return false;
const bytes = new Uint8Array(hex.match(/.{2}/g)!.map((h) => parseInt(h, 16)));
const little = bytes[0] === 1;
const geomType = new DataView(bytes.buffer).getUint32(1, little);
return (geomType & 0xffff) === 1;
} Try / catch
try {
const [x, y] = parseEWKB(hexValue);
} catch (e) {
if (e instanceof Error && /Unsupported geometry type/i.test(e.message)) {
// fall back to a full EWKB decoder (wkx/@turf) for non-Point geometries
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No transactions support in neon-http driver
- crudPolicy requires a read policy
- crudPolicy requires a modify policy
- Your "${f.path.join('->')}" field references a column "${tab
- Failed query: ${queryString} params: ${params}
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/93aa318e7402c531.json.
Report an issue: GitHub.