从postgresql中的函数形式参数接受点几何参数

时间:2015-05-25 07:42:46

标签: postgresql postgis

这是代码:

create function add_point(x integer, y integer) returns void as $$
begin
  insert into auto values(
    'point("'x|| ' '|| y'")',
    'point(0474735 1559415)',
    'point(0474757 1559414)',
    'point(0474751 1559496)',
    'SRID=20137;POLYGON((0474713 1559420, 0474735 1559415, 0474757 1559414, 0474743 1559471, 0474751 1559496, 0474748 1559498, 0474713 1559420))'
  );
end; $$ language plpgsql;

select add_point(0474713, 1559420);

在执行add_point函数期间,它会引发以下错误:

  

错误:语法错误在或附近" x"第7行:插入自动值(   '指向("' x ||'' || y'")','指向(047 .. 。                                             ^   **********错误**********

     

错误:语法错误在或附近" x" SQL状态:42601字符:126

任何想法?

2 个答案:

答案 0 :(得分:1)

显然,您的auto表格后面有5个geometry列。那很好,但这是真的吗?如果没有,则应使用括号分隔单独行上的几何。

您的即时错误与将参数拼接到第一个POINT geometry

有关
insert into auto values(
  'point(' || x || ' ' || y || ')',
  ...

答案 1 :(得分:1)

错误与你制作积分的方式有关。它在其他方面也是低效且容易出错的。当您可以将参数用作数字时,无需使用字符串连接:

let post = PFObject(className: "Post")
//increment like this
post.count += 1
//decrement like this
post.count -= 1

//refresh screen
//call reloadData()

我还会更改其他点定义以使用此格式。这将确保格式,链接或任何东西永远不会出现任何问题。

同样为点设置SRID也可能有用,因为您可以使用INSERT INTO auto VALUES (ST_point(x, y), ...

相关问题