Skip to content

Render PostGIS geometry/geography columns as WKT (PostgreSQL plugin) #1458

@shubhank-saxena

Description

@shubhank-saxena

First off, I really love what you're building with TablePro. The native-multi-DB-open-source niche has been empty for a long time, and the polish on v0.45 is great. Happy to take a crack at implementing this one if you'd be open to a PR; flagging it as an issue first so we can align on approach before I write code.

Problem

When querying a PostgreSQL table with PostGIS geometry or geography columns, the data grid displays the raw EWKB hex string (e.g. 0101000020E61000000000000000008052C0F853E3A59B5C4440) instead of a human-readable representation.

Other native clients (DBeaver, Postico, TablePlus) decode these client-side and show WKT like POINT(-73 40.7237), optionally with a "view on map" affordance. The current behavior in TablePro forces users to wrap every query in ST_AsText(...) manually, which is awkward for SELECT * and breaks ad-hoc table browsing.

Repro:

CREATE EXTENSION postgis;
CREATE TABLE places (id int, name text, point geometry(Point, 4326));
INSERT INTO places VALUES (1, 'a', ST_SetSRID(ST_MakePoint(-73, 40.7237), 4326));
SELECT * FROM places;

Expected: point column shows POINT(-73 40.7237) (or EWKT with SRID).
Actual: point column shows 0101000020E6100000....

Proposed solution

Mirror the approach already shipped for DuckDB in #1329 / v0.45.0: detect spatial column types in result metadata and rewrite the query to wrap matching columns with ST_AsEWKT(col) (EWKT preserves SRID, which plain WKT drops).

One PostgreSQL-specific wrinkle worth flagging up front: PostGIS is an extension, so the type OIDs for geometry and geography are assigned at CREATE EXTENSION time and differ per database. The DuckDB fix could key off the fixed DUCKDB_TYPE_GEOMETRY constant; the PostgreSQL plugin will need to look the OIDs up per connection, e.g.

SELECT oid, typname FROM pg_type WHERE typname IN ('geometry','geography');

cached for the lifetime of the connection. The _tp_cast query-rewrite mechanism from #1329 should otherwise port over directly.

Out of scope for a first pass (but natural follow-ups): map preview panel for geometry cells, raster type support, geography(...) distance display niceties.

Alternatives considered

  • Manual ST_AsText(col) in every query, works but defeats SELECT * and ad-hoc table browsing.
  • Client-side EWKB parsing in Swift without a query rewrite, possible but duplicates logic PostGIS already does correctly server-side, and would need to track the full WKB spec including curved geometries.

Related database type

PostgreSQL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions