我可以在 postgres 函数定义中使用有意义的参数名称而不是 $1、$2 吗?
Can I use meaningful parameter names rather than $1, $2 inside postgres function definition?
我可以使用放在参数列表中的有意义的名称,而不是函数定义中的 $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 = ;
if (reportid is null) then
insert into reports (report_name) values() returning report_id into reportid;
end if;
insert into emails_sent (pid, report_id, date_sent)
values(, reportid, now());
END $$
LANGUAGE plpgsql;
是的,显然我可以在函数定义中直接使用参数名称而没有问题。例如
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;
我可以使用放在参数列表中的有意义的名称,而不是函数定义中的 $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 = ;
if (reportid is null) then
insert into reports (report_name) values() returning report_id into reportid;
end if;
insert into emails_sent (pid, report_id, date_sent)
values(, reportid, now());
END $$
LANGUAGE plpgsql;
是的,显然我可以在函数定义中直接使用参数名称而没有问题。例如
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;