gpt4 book ai didi

postgresql - 列不存在(在查询中创建列)

转载 作者:行者123 更新时间:2023-11-29 13:26:01 25 4
gpt4 key购买 nike

<分区>

我在运行此查询的 SELECT 部分的 postgres 中收到错误“列“距离”不存在”。 “距离”是指给定坐标的两点之间的距离。我怀疑这是一个时间问题?在错误发生之前正确创建函数。

CREATE OR REPLACE FUNCTION pg_temp.earthDistance(lat1 double precision, lng1 double precision, lat2 double precision, lng2 double precision)
RETURNS double precision AS
$BODY$
SELECT
asin(
sqrt(
sin(radians($3-$1)/2)^2 +
sin(radians($4-$2)/2)^2 *
cos(radians($1)) *
cos(radians($3))
)
) * 7918 AS distance;
$BODY$
LANGUAGE sql IMMUTABLE;

SELECT populated_place.name AS populated_place_name,
feature.name AS feature_name,
ROUND(
pg_temp.earthDistance(
populated_place.latitude,
populated_place.longitude,
feature.latitude,
feature.longitude)::NUMERIC,
2) AS distance,
RANK() OVER (PARTITION BY populated_place_name ORDER BY distance) AS rank
FROM populated_place JOIN feature ON
feature.type='summit' AND
populated_place.population>=100000
WHERE distance<=200
ORDER BY populated_place_name, rank;

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com