[英]How can I alter this to run in postgresql?
What needs changing for this to run in postgreSQL? 要在postgreSQL中运行,需要更改什么?
I was given the piece of sql 我得到了一条SQL
UPDATE ACC
SET ACC.ACC_EC = SITESmin.ACC_EC,
ACC.ACC_NC = SITESmin.ACC_NC
FROM ACC
INNER JOIN LATERAL ( SELECT TOP 1
*
FROM SITES
ORDER BY ( acc_ec - site_etg ) * ( acc_ec - site_etg ) + (acc_ncb - site_ntg ) * ( acc_ncb - site_ntg )
) SITESmin;
It seems to be using SET but I do not know why, so if it's not needed drop it. 它似乎正在使用SET,但我不知道为什么,所以如果不需要它,请将其删除。 I am trying to get postgresql to work out distances.
我正在尝试让postgresql解决距离问题。 For every record in file one I have to compare to 3300 records in file 2 and select the nearest.
对于文件1中的每条记录,我必须将其与文件2中的3300条记录进行比较,然后选择最接近的记录。 Received wisdom suggests an array solution for the 3300 but I do not know how to do that.
公认的智慧为3300提供了一种阵列解决方案,但我不知道该怎么做。 Perhaps it it a "sub query" in SQL.
也许它是SQL中的“子查询”。
If I am permitted to upload samples I will do so, though I have the feeling this is not allowed? 如果我被允许上传样品,我会这样做,尽管我感觉不允许这样做?
Here are the filed names 这是文件名
public.acc.Location_Easting_OSGR
public.acc.Location_Northing_OSGR
"public"."Sites"."SITE_ETG"
"public"."Sites"."SITE_NTG"
Try this: 尝试这个:
WITH SITESmin as (
SELECT ACC_EC, ACC_NC
FROM SITES
ORDER BY ( acc_ec - site_etg ) * ( acc_ec - site_etg ) + (acc_ncb - site_ntg ) * ( acc_ncb - site_ntg )
LIMIT 1
)
UPDATE ACC
SET ACC.ACC_EC = SITESmin.ACC_EC,
ACC.ACC_NC = SITESmin.ACC_EC
FROM SITESmin;
If it does not work, please provide the schema and some data to make it easier to reproduce 如果不起作用,请提供架构和一些数据,以使其更易于重现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.