3
我有一個名爲tt的複合類型,用於我所有的plpgsql和plpythonu 過程。是否有某種pl。。是否以一致的方式訪問目錄或 模式,以便派生類型或可迭代結構來返回 ,而無需在plpythonu過程中定義類?我可以通過postgres和plpython共享複合類型
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;