stored-procedures - 我可以在 postgres 和 plpython 之间共享复合类型吗

标签 stored-procedures plpython plpy

我有一个名为 tt 的复合类型,供我所有的 plpgsql 和 plpythonu 使用 程序。有什么东西吗?访问目录的方式或 模式以一致的方式派生类型或可迭代结构以返回 无需在 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;

最佳答案

没有像那样内置的任何东西,但这是一个不错的主意。您可以按照您的指示,通过查询系统目录自己编写。

关于stored-procedures - 我可以在 postgres 和 plpython 之间共享复合类型吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12511431/

相关文章:

stored-procedures - 使用 SQL 代理作业循环调用过程

c# - 无法将参数传递给存储过程: parameters not supplied

mysql - Codeigniter调用存储过程进入事务

python - PL/Python错误 "could not convert SPI error to Python exception"

python - 如何在 Python 中将匹配对聚合到 "connected components"

sql - plpy.notice(msg) 是做什么的?

SQL动态创建存储过程?