我正在尝试编写一个函数,该函数返回由用户定义类型的单列组成的记录,以便我可以使用ResultSet.getObject(int colNumber, Class<T> class)
方法将其提取到Java中。如果我的函数返回的列不止一列,则可以正常工作,但是如果我的函数只有一列,则它将UDT扩展回其组成部分,因此我无法使用所需的方法。例如
create type test as (x int, y int);
create or replace function test()
returns table(test test)
as $$
select (42, 7)::test;
$$ language sql;
create or replace function test2()
returns table(test test, junk boolean)
as $$
select (42, 7)::test, false;
$$ language sql;
运行test2()
以我可以通过所需方法提取的格式给我提供了数据,但test()
没有。如何指定测试的返回值以得到所需的结果?
postgres=# select * from test2();
test | junk
--------+------
(42,7) | f
(1 row)
postgres=# select * from test();
x | y
----+---
42 | 7
(1 row)
我想要的是...
postgres=# select * from test();
test
--------
(42,7)
(1 row)
我认为*是问题。我们在每一列中使用星号。
您需要扩展类型的列,但是当您使用select *
时不能这样做,您需要单独列出这些列。