sql - 函数返回单个列中的数据,而不是 3 个单独的列

标签 sql postgresql

我有一个函数如下:

CREATE FUNCTION public.my_func(...)
  RETURNS TABLE(a integer, b timestamp without time zone, c timestamp without time zone) AS
$BODY$
BEGIN
    create temporary table t1 as
    select ....

RETURN QUERY
WITH RECURSIVE x AS ( working with t1 ..... ) SELECT x.a, x.b, x.c where ....;

当我将其称为“select my_func(1, 2, 3)”时,它会在单个列中返回数据:

result
-----------
(32, "7-dec-2016", "3-mar-2017")

我希望它在 3 个单独的列中返回它。怎么办?

最佳答案

当您调用函数 SELECT my_func(1, 2, 3) 时,您的结果将记录在一个字段中。你需要运行:

SELECT * FROM my_func(1, 2, 3);

关于sql - 函数返回单个列中的数据,而不是 3 个单独的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42172432/

相关文章:

MYSQL:从多个表返回计数

postgresql - 获取 fatal error : server could not be contacted when running pgAdmin4. 'NoneType' 对象没有属性 'value'

sql - Postgres 中单个连接的查询并行化

ruby-on-rails - 查看 heroku 上的数据库

sql - 分区表中如何可以有多个唯一?

mysql - UNION SELECT 的问题

sql - 错误 : column reference "customer" is ambiguous

asp.net - 遇到除零错误

mysql - C语言新手的RDMS?

sql - 执行查询中创建的多个 SQL 字符串