SQLServer地理数据类型使用PowerShell

发布于 2025-01-21 04:11:02 字数 752 浏览 4 评论 0原文

我正在使用PowerShell 4.0和SQL Server 2014

我有一个SQL Server数据库表,其中包含“地理”数据类型字段。当使用SQL Server Management Studio(SSM)查看时,地理值看起来很长(40个字符)十六进制号,即0xE610000101C11FCF .....

我想导出某些记录以导入同一数据库的副本。为此,我正在使用CSV-EXPORT和CSV-IMPORT。

首先,我阅读了记录:

$sqlcmd = "SELECT * FROM myTable WHERE ID = 123"

$record = Invoke-Sqlcmd -Query $sqlcmd -ServerInstance $s -Database $d -Username $u -Password $p -MaxCharLength 8000 -QueryTimeout 0

该记录包含ID和一个地理成员。使用PowerShell ISE查看返回的记录:

ID   : 123
Geo  : POINT (123.456, 11.22) 

似乎已将地理值返回。除某些非常特殊的值外,随后的CSV-EXORT和CSV-IMPORT/INSERT代码在引擎盖下处理此操作。这会导致验证失败,因为目标数据库值不等于源数据库值。

我猜想转换到/从点引起了问题。

为了解决这个问题,我认为我应该阅读并编写地理数据的原始六角值。 如何编写返回原始RAW HEX数据的选择语句?

I am using Powershell 4.0 and Sql Server 2014

I have a Sql Server database table which contains a 'geography ' data type field. When viewed using SQL Server Management Studio (SSMS) the geography values look like very long (40 Char) hex numbers, ie 0xE610000101C11FCF.....

I want to export certain records for importing into a copy of the same database. I am using csv-export and csv-import for this.

First I read a record:

$sqlcmd = "SELECT * FROM myTable WHERE ID = 123"

$record = Invoke-Sqlcmd -Query $sqlcmd -ServerInstance $s -Database $d -Username $u -Password $p -MaxCharLength 8000 -QueryTimeout 0

The record contains an ID and a geography member. Using PowerShell ISE to view the record returned:

ID   : 123
Geo  : POINT (123.456, 11.22) 

It seems the geography value has been returned as a POINT. The subsequent csv-export and csv-import/INSERT code handle this under the hood, EXCEPT for some very particular values. This causes validation to fail since the target database value does not equal the source database value.

I'm guessing the conversion to/from POINT is causing the problem.

To solve this problem I think I should read and write the raw hex value of the geography data.
How can I write a SELECT statement which returns the original raw hex data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文