在plpgsql函数中使用单引号作为值

时间:2017-07-25 09:08:14

标签: postgresql plpgsql postgresql-9.3

我有postgresql函数,它接受4个参数

CREATE OR REPLACE FUNCTION public.manual_table_parsing_monthly_custom_edits(
schema_name text,
main_permit text,
manual_table text,
permit_num text)
RETURNS void AS
$BODY$
DECLARE
    e record;
    load_move_count double precision;
BEGIN
  EXECUTE format('Insert into %I.%I(permit_date,permit_number,year,month_number,
    report_permit_date,job_category,address,legal_description,neighbourhood,neighbourhood_number,
    job_description,work_type,floor_area,construction_value,zoning,units_added,
    latitude,longitude,location,count,building_type,building_type_number,filter,community,
    groups,plan,block,lot,unit_id,dwelling,condo_fh,developer,builder,unit_address,construction_type,geom)
            select permit_date,permit_number,year,month_number,
    report_permit_date,job_category,address,legal_description,neighbourhood,neighbourhood_number,
    job_description,work_type,floor_area,construction_value,zoning,units_added,
    latitude,longitude,location,count,building_type,building_type_number,filter,community,
    groups,plan,block,lot,unit_id,dwelling,condo_fh,developer,builder,unit_address,construction_type,geom
from %I.%I
where flag like ''move'' or flag like ''load'' and permit_number 
=%I',schema_name,main_permit,schema_name,manual_table,permit_number);

在where语句中使用的函数 permit_number 中的最后一个参数引发了错误no column' yyyy'。这是因为%I在双引号内取值。我应该如何编辑,以使值在单引号内

1 个答案:

答案 0 :(得分:2)

根据documentiaion %I应该用于标识符,%L应该用于文字值。

还应使用$$引用,以便于阅读您的功能...