"错误:查询没有结果数据的目的地"在PL / pgSQL函数中

时间:2016-04-08 21:18:12

标签: postgresql plpgsql

我想创建一个函数,可用于将数据插入表uuser并返回数据类型为uid的{​​{1}}。

serial
CREATE TABLE uuser (
  uid serial PRIMARY KEY
, user_name text NOT NULL
, last_login timestamptz NOT NULL DEFAULT current_timestamp
, real_name text
, age int
, city text
, CHECK (age > 0 and age < 140)
);

CREATE OR REPLACE FUNCTION ins_uuser(p_user_name text
                                   , p_real_name text
                                   , p_age int
                                   , p_city text)
RETURNS integer AS
$$
BEGIN
INSERT INTO uuser(user_name, last_login, real_name, age, city)
VALUES($1, CURRENT_TIMESTAMP, $2, $3, $4)
RETURNING uid;
END;
$$
LANGUAGE plpgsql VOLATILE;

SELECT ins_uuser('Joker', 'Jack', 18, 'New York') AS uuser_id;

0 个答案:

没有答案
相关问题