Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There is no direct equivalent of OCIDefineArrayOfStruct() or OCIBindArrayOfStruct in PostgreSQL. However, PostgreSQL provides the capability to deal with array types, and you can use array types to achieve similar functionality.

To bind an array to a parameter in PostgreSQL, you can use a parameter of array type. To fetch an array of structures in PostgreSQL, you can use an array of composite types (i.e., a custom data type that can contain multiple fields).

Here's an example of how to define an array of composite types in PostgreSQL:

CREATE TYPE mycomptype AS ( field1 integer, field2 text );

To fetch an array of this composite type, you can use the following SQL statement:

SELECT ARRAY(SELECT ROW(1, 'foo')::mycomptype, ROW(2, 'bar')::mycomptype);

This statement will return an array with two elements, each of which is a composite type containing two fields (an integer and a text field).

Similarly, to bind an array of values to a parameter in PostgreSQL, you can use an array parameter type. For example:

CREATE FUNCTION testfunc(myarray integer[]) RETURNS integer AS $$ BEGIN RETURN myarray[1]; END; $$ LANGUAGE plpgsql;

In this example, the testfunc() function takes an array of integers as a parameter and returns the first element of the array. You can call this function with an array parameter as follows:

SELECT testfunc('{1,2,3}');