Prabha S
asked on
How to pass array of objects from jpa to postgresql function
Hi,
we have postgresql function which accepts tags_type composite type as a input parameter.
How can we pass the values to the function using jpa.
we have postgresql function which accepts tags_type composite type as a input parameter.
How can we pass the values to the function using jpa.
create type tags_type as(tag text, tag_url text)
CREATE OR REPLACE FUNCTION public.create_article(title text, tags tags_type[])
RETURNS integer
AS $function$
DECLARE
id int2;
t tags_type;
begin
insert into articles(a_title)
values(title);
id := currval('article_id_seq');
FOREACH t in array tags
loop
insert into atricle_tags(at_id, at_tag, at_url_name)
values(id, t.tag, t.tag_url);
end loop;
return id;
end;
$function$
LANGUAGE plpgsql
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
https://blog.2ndquadrant.com/using-java-arrays-to-insert-retrieve-update-postgresql-arrays/