I need to do a bulk insert (via bcp
) into a SQL Server table with geometry data. I figured out how to get the operation working generally, however, there are a few criteria/issues that I have been having trouble with:
SRID
. I am working with geometry columns, but I need to have SRID = 4326
. I am ok with either a solution that lets me set them per row, or something that would allow me to configure the default SRID
for a column.bcp
to insert the rows and then making an update pass to set SRIDs on all of them.I have seen examples of .NET applications being able to do this, but I am working from NodeJS. I'm not even sure if there is some SQL Server API that would let me do this, or if the .NET classes were using the UDT binary and had internal code to make the validity determination.
So my questions are:
I have tried many things.
varchar
column and wkt. The SRID
was set to 0 (SQL Server's default for geometry values)SRID
for a column (I haven't found anything)geometry::STGeomFromText
with an SRID
. I have found nothing.Posting an answer for the sake of those who may come looking later:
The original question "Is this possible with SQL Server bcp from NodeJS?" remains unanswered.
However, @siggemannen suggested serializing my recordset into JSON, which can then be sent to SQL Server in a VARCHAR(MAX)
and turned back into a table value using the OPENJSON
function. The columns of this table value can then be processed in SQL as you would when SELECTing from any other table.
This allows efficiently processing datasets at a size that meets my use case.