【发布时间】:2017-05-18 12:25:50
【问题描述】:
我有一个x, y 点的表,我需要找到表中其他行少于三行且具有更高x 值或更高y 值的点。
x | y
-----+-----
85 | 996
109 | 989
116 | 987
164 | 983
create or replace function sk(tableName text)
returns integer
as $$
declare
count integer;
r record;
begin
count :=3;
for r in execute 'select * from TABLE'
if
loop
count := count - 1;
end loop;
return count;
end
$$ language plpgsql;
预期结果是一个新视图,其中只有那些小于 3 且大于 x 或 y 的点。
【问题讨论】:
-
编辑您的问题并显示您想要的结果。
-
"psql" 不是 Postgres 的有效名称,这是标准命令行界面的名称。而且您不需要“循环”,您需要解决问题。循环是一种可能的技术,在任何 RDBMS 中很少是一种有效的方法。我冒昧地澄清一下。
标签: sql postgresql plpgsql