我有一个名为tt的复合类型,所有plpgsql和plpythonu过程都要使用它。有没有什么plpy。以一致的方式访问目录或架构以便派生类型或可迭代结构以返回的方法,而不必在plpythonu过程中定义类?
CREATE TYPE tt AS (id integer, name text);
CREATE OR REPLACE FUNCTION python_setof_type() RETURNS SETOF tt AS $$
#-- i want this to be dynamic or to have it's attributes pulled from the tt type
class tt:
def __init__(self, id, name):
plpy.info('constructed type')
self.idx = 0
self.id = id
self.name = name
def __iter__ (self):
return self
def next (self):
if (self.idx == 1):
raise StopIteration
self.idx += 1
return ( self )
return tt(3, 'somename')
#-- was hoping for something like
#-- give me 1 record
#-- return plpy.schema.tt(3, 'somename')
#-- give me 2 records
#-- return plpy.schema.tt([3, 'somename'], [1, 'someornothername'])
#-- give me a no records
#-- return plpy.schema.tt([])
$$ LANGUAGE plpythonu;发布于 2012-11-01 00:14:59
没有像这样的东西,但这是一个很好的想法。正如您所指出的,您可以通过查询系统目录自己编写它。
https://stackoverflow.com/questions/12511431
复制相似问题