我的交叉表无法正常运行

时间:2019-01-07 11:00:38

标签: postgresql

  

错误:“ VALUES”第14行或附近的语法错误:,$$ VALUES('01'),   ('02'),('03'),('04'),('05'),('06'),...

CREATE OR REPLACE FUNCTION search_id_person(id_person1 integer,sal integer) RETURNS VOID AS
$$
BEGIN

SELECT *
FROM   crosstab(
   'select personely.person.name,personely.person.family,unit.title,org.orgname(org.unit.id_child),mahane.sal ,personely.mahane.mah,personely.mahane.sum1
from personely.mahane
inner join personely.person on personely.person.id_person=personely.mahane.id_person
    inner join personely.karkard on personely.person.id_person=personely.karkard.id_person
    inner join org.unit on org.unit.id_unit=personely.person.id_unit
    where mahane.sal::integer = $2 and personely.person.id_person=$1
    ORDER  BY personely.person.id_person   ' 
    , $$VALUES ('01'), ('02'), ('03'), ('04'), ('05'), ('06'), ('07'), ('08'), ('09'), ('10'), ('11'), ('12')$$
   ) AS a ("نام" text,"نام خانوادگی" text,"واحد" text,"سازمان" text,"سال" text, "فروردین" int , "اردیبهشت" int, "خرداد" int, "تیر" int, "مرداد" int, "شهریور" int, "مهر" int, "آبان" int, "آدر" int, "دی" int, "بهمن" int, "اسفند" int);                                                                                
END ;

1 个答案:

答案 0 :(得分:0)

您已嵌套$$引号。替换

$$VALUES ('01'), ('02'), ('03'), ('04'), ('05'), ('06'), ('07'), ('08'), ('09'), ('10'), ('11'), ('12')$$ 

使用

$values$VALUES ('01'), ('02'), ('03'), ('04'), ('05'), ('06'), ('07'), ('08'), ('09'), ('10'), ('11'), ('12')$values$