I have a table Juego
which has 4 columns nombre, tipo, autor, proveedor
, the function that I create allows me to enter data filtering according to characters correctly, but I would like to write the columns and the value of the array that I should enter in said column , considering that this would not be practical if I had many columns, I would like to know if someone could help me how to perform this function dynamically since I have not yet had the solution.
Example of how the function you create works
Data:
halo*accion*juan*pedro|gow*accion*juan*gabriel|the last of us*aventura*lucius*jose
The filtering function as follows
nombre | tipo | autor | proveedor
halo |accion | juan | gabriel
gow |accion | juan | gabriel
tlou |aventur|lucius | jose
Table
create table juego(nombre varchar(60),tipo varchar(60),autor varchar(60), proveedor text);
Function created
CREATE OR REPLACE FUNCTION insrt(var text)
RETURNS integer AS $BODY$
DECLARE
fila text[];
row text;
colm text[];
BEGIN
fila := regexp_split_to_array(var, E'\|');
FOREACH row IN ARRAY fila
LOOP
colm := regexp_split_to_array(row, E'\*');
insert into juego values(colm[1],colm[2],colm[3],colm[4]);
END LOOP;
RETURN 1;
END;