Forum Discussion

junkyardnils's avatar
junkyardnils
Copper Contributor
Sep 02, 2025

Fail to OPENROWSET insert geometry data from parquet

Hi!

I'm trying to insert geometry data (WKB) from a parquet file to a data base table. I manage to get it working for small geometries but it's failing for lager geometriers. Here is the code:

INSERT db.s.t 
  SELECT geometry::STGeomFromWKB(a.geom,1) 
    FROM OPENROWSET
    (
      BULK 'path_to.parquet',
      FORMAT = 'PARQUET',
      DATA_SOURCE = 's3_sorce'
    ) AS a

The failure:

String or binary data would be truncated while reading column of type 'VARBINARY(8000)'. Check ANSI_WARNINGS option.... 

Seems as if the geometry type is not recognized. Is there a way around this?

1 Reply

  • carlwalk's avatar
    carlwalk
    Copper Contributor

    This one’s basically SQL Server being a little too clever for its own good. When OPENROWSET reads the Parquet file, it guesses the geometry column should be a VARBINARY(8000), and that works fine until it hits a geometry that’s bigger than 8 KB — then everything blows up with a truncation error. Nothing is actually wrong with your geometry data or STGeomFromWKB; the data is getting chopped before SQL Server even has a chance to convert it. The usual workaround is to stop SQL Server from guessing: load the data into a staging table with a VARBINARY(MAX) column (or explicitly cast it if possible) and then convert it to geometry from there. Once you do that, the inserts behave normally.

Resources