【问题标题】:Return a table of custom type in Postgresql在 Postgresql 中返回自定义类型的表
【发布时间】:2018-11-06 20:38:58
【问题描述】:

我有这样的功能

foo() RETURNS TABLE(col1,col2,col3) AS....

但我想更改它以返回自定义类型

CREATE TYPE mytype AS
   (col1,col2,col3);

还有:

foo() RETURNS mytype AS....

但我不知道该怎么做

【问题讨论】:

  • 这应该会有所帮助:stackoverflow.com/a/17865708/939860
  • 谢谢!我的下一个问题是如何将自定义类型迭代到函数中,但我可以在您的回答中看到,在这种情况下,我必须返回一个 table(col1,col2....)

标签: sql postgresql


【解决方案1】:

您可以将returns setof 与自定义类型一起使用:

create function foo() 
  returns setof mytype
as
...

【讨论】:

    猜你喜欢
    • 2011-01-03
    • 1970-01-01
    • 2014-02-27
    • 2013-07-05
    • 2013-08-16
    • 2016-02-15
    • 2017-04-13
    • 2014-08-21
    • 2020-05-09
    相关资源
    最近更新 更多