Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Union all geometry in a SQL Server table like GeomUnion in Postgres

Just to clarify up-front: I'm talking about unioning geometry, not the SQL keyword UNION.

I'm trying to move some spatial data from Postgres with PostGIS to SQL Server 2008. It was fine until I saw a statement like this:

SELECT GeomUnion(the_geom) FROM some_table

This unions all geometry in that column and return it as one result (similar to how COUNT works). As far I know, SQL Server only has the STUnion function, which unions one geometry with another. Is there any way to do something similar to the Postgres way?

If it helps, the STUnion function works like this:

SELECT first_geometry_column.STUnion(second_geometry_column) FROM some_table
like image 385
Brendan Long Avatar asked Jul 20 '10 18:07

Brendan Long


People also ask

Does SQL Server support union all?

The SQL Server UNION ALL operator is used to combine the result sets of 2 or more SELECT statements. It returns all rows from the query and it does not remove duplicate rows between the various SELECT statements.

Can we use union for same table?

The SQL UNION operator Put differently, UNION allows you to write two separate SELECT statements, and to have the results of one statement display in the same table as the results from the other statement.

What is Union in SQL Server?

The SQL UNION Operator The UNION operator is used to combine the result-set of two or more SELECT statements. Every SELECT statement within UNION must have the same number of columns. The columns must also have similar data types. The columns in every SELECT statement must also be in the same order.


1 Answers

Is the UnionAggregate function SQL2012 only?

SELECT geography::UnionAggregate( geometry ) FROM some_table

Hmm guess so. http://technet.microsoft.com/en-us/library/ff929095.aspx

like image 173
nportelli Avatar answered Nov 15 '22 11:11

nportelli