P
P
Pavel2018-06-25 23:40:18
PostgreSQL
Pavel, 2018-06-25 23:40:18

How to pass an array of custom types to a function?

There are the following types:

CREATE TYPE _goods_item AS (goods_id bigint, point_id bigint, quantity integer, volume integer, is_perishable boolean);
CREATE TYPE _distance_item AS (point_id bigint, distance integer);
CREATE TYPE _point_item AS (point_id bigint, point_type bigint, distances _distance_item[]);

There is a function:
CREATE OR REPLACE FUNCTION _generate( goods_item _goods_item[], point_item _point_item[] ) RETURNS SETOF integer AS '$pg', '_generate' LANGUAGE C STRICT STABLE;

How to call it correctly?
For
CREATE OR REPLACE FUNCTION _generate2( goods_item _goods_item[], point_item _distance_item[] ) RETURNS SETOF integer AS 'pg', '_generate2' LANGUAGE C STRICT STABLE;

The call looks like this:
select _generate2('{"(1,3,3,9,false)", "(10,30,30,90,false)"}'::_goods_item[], '{"(22,332)", "(243,24323)", "(243,24323)"}'::_distance_item[]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Paul, 2018-06-26
@Azimuth

I asked it myself - I answer it myself: I
changed it to array[] and it became clearer and it worked:

select _generate(array[(1,3,3,9,false), (10,30,30,90,false)]::_goods_item[], array[(10,23001, array[(10,20), (4342,20)]::_distance_item[]), (332,23000, array[(10,20), (2212,232), (23424,244)]::_distance_item[])]::_point_item[]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question