小编cra*_*ton的帖子

用于INSERT多个表中的动态列列表的函数

我想在PostgreSQL中做这样的事情.

我试过这个:

CREATE or replace FUNCTION create_patient(_name text, _email text, _phone text
     , _password text
     , _field1 text, _field2 text, _field3 timestamp, _field4 text
     , OUT _pid integer, OUT _id integer
    ) RETURNS record AS
$$
DECLARE
    _id integer;
    _type text;
    _pid integer;
BEGIN
    _type := 'patient';

    INSERT into patients (name, email, phone, field1, field2, field3)
    VALUES (_name, _email, _phone, _field1, _field2, _field3)
    RETURNING id into _pid;

    INSERT into users (username, password, type, pid, phone, language)
    VALUES (_email, …
Run Code Online (Sandbox Code Playgroud)

postgresql stored-procedures insert plpgsql postgresql-9.1

1
推荐指数
1
解决办法
3690
查看次数