Postgresql 需要不同于postgres函数的返回格式
我有一张桌子Postgresql 需要不同于postgres函数的返回格式,postgresql,Postgresql,我有一张桌子 CREATE TABLE reward_transactions ( uid bigint NOT NULL, reward_type text NOT NULL, count bigint, last_update timestamp with time zone DEFAULT now() ) 和一个函数 CREATE FUNCTION store_reward_transaction(bigint, text) returns record LANG
CREATE TABLE reward_transactions
(
uid bigint NOT NULL,
reward_type text NOT NULL,
count bigint,
last_update timestamp with time zone DEFAULT now()
)
和一个函数
CREATE FUNCTION store_reward_transaction(bigint, text) returns record
LANGUAGE plpgsql
AS $_$
declare
_record record;
begin
update reward_transactions set count = count + 1, last_update = now() where uid = $1 and reward_type = $2::text returning count, last_update::timestamp with time zone into _record;
if found then
return _record;
end if;
begin
insert into reward_transactions (uid, count, reward_type) values ($1, 1, $2::text) returning count, last_update::timestamp with time zone into _record;
return _record;
exception when unique_violation then
update reward_transactions set count = count + 1, last_update = now() where uid = $1 and reward_type = $2::text returning count, last_update::timestamp with time zone into _record;
return _record;
end;
end
$_$;
问题是,我如何才能让它不返回行:[{store_renward_transaction:'(12,“2014-07-18 17:29:39.780207-05”)}
,而是返回类似于从原始表中选择的内容(即列名完整),我已尝试将其作为tablename%ROWTYPE返回,使用自定义类型和其他一些东西,我似乎无法获得所需的输出。使用9.3.3尝试以下操作:
SELECT * FROM store_reward_transaction(4,'blah') f(count bigint, last_update timestamp with time zone);
感谢您让我走上了正确的轨道,相应地更新您的答案
select*from store_reward_transaction(4,'blah')作为f(count bigint,last_update timestamp with time zone)代码>我会标记它,您的原始答案会导致错误:返回“record”的函数需要列定义列表