错误:列索引超出范围:1,列数:0

use*_*056 7 postgresql wso2-data-services-server

我正在使用wso2dss 3.0.0.我正在尝试执行postgresql查询,即

SELECT addressid, geocode
FROM maddress
WHERE geocode::point <@ circle '((18.9750,72.8258), 5)';
Run Code Online (Sandbox Code Playgroud)

它在PostgreSQL中工作正常.当我在wso2dss中使用相同的查询时

SELECT addressid, geocode
FROM maddress
WHERE geocode::point <@ circle '((?,?), ?)';    
Run Code Online (Sandbox Code Playgroud)

它给我的错误如下:

DS Fault Message: Error in 'SQLQuery.processNormalQuery'
DS Code: DATABASE_ERROR
Source Data Service:-
Name: Geofence_DataService
Location: /Geofence_DataService.dbs
Description: N/A
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: adding_geofence_op
Current Params: {longitude=72.8258, radius=4, latitude=18.9750}
Nested Exception:-
DS Fault Message: Error in 'createProcessedPreparedStatement'
DS Code: UNKNOWN_ERROR
Nested Exception:-
org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.
Run Code Online (Sandbox Code Playgroud)

如果我删除" ' "(引号)圆圈,那么它也不会执行.查询''看起来像这样:

SELECT addressid,geocode FROM maddress WHERE geocode :: point <@ circle((?,?),?);

它会给出以下错误:

Caused by: javax.xml.stream.XMLStreamException: DS Fault Message: Error in 'SQLQuery.processNormalQuery'
DS Code: DATABASE_ERROR
Source Data Service:-
Name: Geofence_DataService
Location: /Geofence_DataService.dbs
Description: N/A
Default Namespace: http://ws.wso2.org/dataservice
Current Request Name: geofence_op
Current Params: {longitude=72.8258, radius=4, latitude=18.9750}
Nested Exception:-
org.postgresql.util.PSQLException: ERROR: function circle(record, double precision) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type cast
Run Code Online (Sandbox Code Playgroud)

但是圈子是PostgreSQL的内置地理功能,那么是否有必要编写显式函数?否则确切错误在哪里?即使我把输入参数的查询作为我在PostgreSQL中执行,然后它也在工作.如果那么为什么它不接受动态参数?请告诉我..

Erw*_*ter 6

几何类型可以以多种方式输入.

  • 在第一种形式中,您的?参数不会被值替换,因为它们是字符串的文字部分.所以预计会有0个参数......

  • 在没有单引号的第二种形式中,您的?参数被替换,但((18.9750,72.8258), 5)被解释为行类型,​​但不起作用circle().

您正在尝试调用circle()带a point和a 的函数double precision("center and radius to circle").这些是有效的语法变体:

SELECT circle '((18.9750,72.8258), 5)'        AS cast_literal
     ' <(18.9750,72.82580),5>'::circle        AS cast_literal2
     , circle(point '(18.9750,72.8258)', '5') AS literal_point_n_radius
     , circle(point(18.9750,72.8258), '5')    AS point_n_literal_radius
     , circle(point(18.9750,72.8258), 5)      AS point_n_radius
Run Code Online (Sandbox Code Playgroud)

SQL小提琴.
演员::text只是为了消除SQL小提琴中的混乱显示

在您的情况下,要提供数值(不是字符串文字),请使用最后一个表单,它应该工作:

SELECT addressid, geocode
FROM   maddress
WHERE  geocode::point <@ circle(point(?,?), ?);
Run Code Online (Sandbox Code Playgroud)

如果wso2dss(这是我所没有的经验),不接受功能,你必须使用的前两种形式之一,并提供一个单一的参数作为字符串字面量:

SELECT addressid, geocode
FROM   maddress
WHERE  geocode::point <@ circle ?;
Run Code Online (Sandbox Code Playgroud)

...其中参数是上面显示的连接文字.

可以让Postgres进行连接并仍然传递三个数值:

SELECT addressid, geocode
FROM   maddress
WHERE  geocode::point <@ ('(('::text || ? || ',' || ? || '),' || ? || ')')::circle;
Run Code Online (Sandbox Code Playgroud)