我创建了一个存储在临时表json数据中的函数推广列。但是当我运行它时,它无法识别 json_populate_recordset 函数。
创建序列proveedorcuadrillarecurso_seq
CREATE SEQUENCE proveedorcuadrillarecurso_seq
INCREMENT 1
MINVALUE -9223372036854775808
MAXVALUE 9223372036854775807
START 1
CACHE 1;
创建表证明者表示
CREATE TABLE proveedorcuadrillarecurso
(
id integer NOT NULL DEFAULT nextval('proveedorcuadrillarecurso_seq'::regclass),
idproveedorcuadrilla integer NOT NULL,
idrecurso integer NOT NULL,
cantidad numeric(10,2) NOT NULL,
CONSTRAINT pk_proveedorcuadrillarecurso PRIMARY KEY (id)
)
创建函数proveedorcuadrillarecurso_nuevomasivo_pa
CREATE OR REPLACE FUNCTION proveedorcuadrillarecurso_nuevomasivo_pa(
par_idproveedorcuadrilla integer,
par_data text
)
RETURNS void AS
$BODY$
DECLARE
var_IDPARENT INT;
var_IdRecurso INT;
var_Cantidad NUMERIC(10, 2);
BEGIN
CREATE TEMPORARY TABLE "#tablaExtra"(
parent_ID INT NOT NULL,
IdRecurso INT,
Cantidad NUMERIC(10, 2),
procesado INT NOT NULL DEFAULT 0
);
INSERT INTO "#tablaExtra"
SELECT * FROM json_populate_recordset(null::"#tablaExtra", par_data);
WHILE EXISTS (SELECT * FROM "#tablaExtra" WHERE procesado = 0) LOOP
SELECT parent_ID, IdRecurso, Cantidad
INTO var_IDPARENT, var_IdRecurso, var_Cantidad
FROM "#tablaExtra"
WHERE procesado = 0
ORDER BY parent_ID NULLS FIRST
LIMIT 1;
BEGIN
INSERT INTO ProveedorCuadrillaRecurso (IdProveedorCuadrilla, IdRecurso, Cantidad)
VALUES (par_IdProveedorCuadrilla, var_IdRecurso, var_Cantidad);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
BEGIN
RAISE NOTICE 'Ocurrio un Error Inesperado... Consultar con el Administrador de Servicios!';
END;
END;
UPDATE "#tablaExtra"
SET procesado = 1
WHERE parent_ID = var_IDPARENT;
END LOOP;
DROP TABLE IF EXISTS "#tablaExtra";
END;
$BODY$
LANGUAGE plpgsql;
Excecute Query ::
select proveedorcuadrillarecurso_nuevomasivo_pa(1,'[{"parent_ID":67272,"IdRecurso":123,"Cantidad":152,"procesado":0}]');
错误:
ERROR: function json_populate_recordset("#tablaExtra", text) does not exist
LINE 2: SELECT * from json_populate_recordset(null::"#tablaExtra...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: INSERT INTO "#tablaExtra"
SELECT * from json_populate_recordset(null::"#tablaExtra", par_data)
CONTEXT: PL/pgSQL function proveedorcuadrillarecurso_nuevomasivo_pa(integer,text) line 27 at SQL statement
********** Error **********
ERROR: function json_populate_recordset("#tablaExtra", text) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Context: PL/pgSQL function proveedorcuadrillarecurso_nuevomasivo_pa(integer,text) line 27 at SQL statement
我从http://www.postgresql.org/docs/9.3/static/functions-json.html
获得了方法的参考