【问题标题】:ERROR : The column index is out of range: 1, number of columns: 0错误:列索引超出范围:1,列数:0
【发布时间】:2015-02-13 08:38:42
【问题描述】:

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

SELECT addressid, geocode
FROM maddress
WHERE geocode::point <@ circle '((18.9750,72.8258), 5)';

它在 PostgreSQL 中运行良好。当我在 wso2dss 中使用相同的查询时,即

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

它给了我这样的错误:

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.

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

选择地址ID,地理编码 发件人地址 WHERE geocode::point

它会给出以下错误:

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

但是circle是PostgreSQL内置的地理函数,那有必要写显式函数吗?否则确切的错误在哪里?即使我在 PostgreSQL 中执行时使用输入参数输入查询,它也可以正常工作。如果是这样,那么为什么它不接受动态参数?请告诉我..

【问题讨论】:

  • 我不知道 wso2dss 但问题似乎是如何将参数拼接到定义圆的字符串中。不带引号的第二个选项是完全错误的,因为现在 PostgreSQL 将 circle ( ... ) 视为一个没有足够模式的函数。从 wso2dss 查看参数是如何放入查询中的。
  • 是的..并且 wso2dss 无法接受功能..这就是问题

标签: postgresql wso2dss


【解决方案1】:

Geometric types可以多种方式输入。

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

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

您正在尝试调用采用pointdouble precision(“圆心和半径”)的geometric function 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

SQL fiddle.
转换为 ::text 只是为了清理 SQL 小提琴中的混乱显示

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

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

如果 wso2dss(我没有经验)不接受函数,您必须使用前两种形式之一并提供 single 参数作为字符串文字:

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

... 其中参数是上面显示的串联文字。

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

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

【讨论】:

  • @user3129056:酷。哪种变体适合您?
  • SELECT addressid, geocode FROM maddress WHERE geocode::point
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-24
  • 1970-01-01
  • 2012-09-20
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
相关资源
最近更新 更多