【问题标题】:How to determine the obtect's attribute and its correct function return?如何确定对象的属性及其正确的函数返回?
【发布时间】:2019-12-28 22:19:32
【问题描述】:

我将这个新函数包含到this S2geometry "plug" 中,该函数调用this Python API... 这很简单,但我无法调试和发现正确的 Python 对象属性和数组数据类型,以转换为 PostgreSQL basic类型。

CREATE FUNCTION s2_token_get_vertex(token text, k int,  OUT debug text)
AS $f$
  import s2sphere
  point = s2sphere.Cell( s2sphere.CellId.from_token(token) ).get_vertex(k)
  return ''.join(map(str,point))
$f$ LANGUAGE plpython3u IMMUTABLE;
  • return type(point)s2sphere.sphere.Point
  • return point.__dict__{'_Point__point': (0.20907532445858387, -0.7283167971253012, 0.6525658217587561)}
  • return map(str,point)0.20907532445858387-0.72831679712530120.6525658217587561
  • return str( point[1] )<class 'float'>

return point 是我为 PostgreSQL 测试的许多替代方案中的任何一个返回的错误:float[]float4[](OUT x float, OUT y float, OUT z float) 的元组...

如何判断point.attribute及其正确的函数返回?


所有线索都说,最接近正确的是在 Python 代码处使用 return point,并在 PostgreSQL 函数返回处使用 OUT r float[]。但是:

 ERROR:  invalid memory alloc request size 18446744073709551608
 CONTEXT:  while creating return value

【问题讨论】:

    标签: python postgresql introspection


    【解决方案1】:

    也许 PostgreSQL 无法解释数组大小,并被认为是任意长度...这个 Python 返回的固定大小数组解决了这个问题

    CREATE or replace FUNCTION s2_token_get_vertex(token text, k int,  OUT r float[])
    AS $f$
      import s2sphere
      point = s2sphere.Cell( s2sphere.CellId.from_token(token) ).get_vertex(k)
      return (point[0],  point[1],  point[2])
    $f$ LANGUAGE plpython3u IMMUTABLE;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-11
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      相关资源
      最近更新 更多