传递一个对象(.net或json对象)作为postgresql函数的输入参数

问题描述 投票:1回答:1

我刚刚开始学习postgresql,我想发送一个c#对象作为postgresql函数(storedprocedure)的参数。

即假设我有一个名为userdetails的类,其中包含用户名,密码,DOB等字段,

如何直接将此对象发送到该函数并从该对象中检索每个字段,然后插入所需表的相应列?

sql json postgresql
1个回答
1
投票

这是以json为参数的函数示例:

create or replace function works_with_json(_j IN json) returns boolean as
$$
declare
begin
    raise info '%', 'a = "'||(_j->>'a')||'"';
    raise info '%', 'b = "'||(_j->>'b')||'"';
    return _j->>'c';
end;
$$ language plpgsql;

select works_with_json ('{"a":"Some string","b":9, "c": true}');
© www.soinside.com 2019 - 2024. All rights reserved.