我可以使用我在参数列表中放置的有意义的名称,而不是函数定义中的$ 1,$ 2吗?
CREATE OR REPLACE FUNCTION add_report_email(
reportname1 text,
personid2 integer )
RETURNS integer AS
$$
DECLARE reportid integer;
BEGIN
select report_id into reportid from reports where report_name = $1;
if (reportid is null) then
insert into reports (report_name) values($1) returning report_id into reportid;
end if;
insert into emails_sent (pid, report_id, date_sent)
values($2, reportid, now());
END $$
LANGUAGE plpgsql;
答案 0 :(得分:0)
是的,显然我可以在函数定义中直接使用参数名称而不会出现问题。例如
CREATE OR REPLACE FUNCTION add_report_email(
reportname text,
personid integer )
RETURNS void AS
$$
DECLARE reportid integer;
BEGIN
-- add the report name into reports table if it does not exist
select report_id into reportid from reports where report_name = lower(reportname);
if (reportid is null) then
insert into reports (report_name) values(lower(reportname)) returning report_id into reportid;
end if;
insert into report_emails_sent (pid, report_id, date_sent)
values(personid, reportid, now());
END $$
LANGUAGE plpgsql;