Arrays

Use of Array Types

Before the use of arrays, an array type needs to be defined.

Define an array type immediately after the AS keyword in a stored procedure. The definition method is as follows:

TYPE array_type IS VARRAY(size) OF data_type;

In the preceding information:

  • array_type: indicates the name of the array type to be defined.
  • VARRAY: indicates the array type to be defined.
  • size: indicates the maximum number of members in the array to be defined. The value is a positive integer.
  • data_type: indicates the types of members in the array to be created.

NOTE:

  • In openGauss, an array automatically increases. If an access violation occurs, a null value is returned, and no error message is reported.
  • The scope of an array type defined in a stored procedure takes effect only in this stored procedure.
  • It is recommended that you use one of the preceding methods to define an array type. If both methods are used to define the same array type, openGauss prefers the array type defined in a stored procedure to declare array variables.
  • data_type can also be the record type defined in a stored procedure (anonymous blocks are not supported), array or set type defined in the stored procedure.
  • When declaring a nested array, that is, when the data_type of an array_type is defined to be an array, a record or a set, the maxium layers of nested type allowed is 6. Also, it's not allowed to assign an array variable or a table variable to a nested array's element directly

openGauss supports access to array elements by using parentheses, and it also supports the extend, count, first, last, prior, exists, trim, next, and delete functions. However, they're not recommended for accessing elements of nested arrays that are refered by subscripts (even if the elements are of array or table type).

NOTE:

  • If a stored procedure contains a DML statement (such as SELECT, UPDATE, INSERT, and DELETE), you are advised to use square brackets to access array elements. Using parentheses will access arrays by default. If no array exists, function expressions will be identified.
  • When the CLOB size is greater than 1 GB, the table of type, record type, and CLOB cannot be used in the input or output parameter, cursor, or raise info in a stored procedure.
Feedback
编组 3备份
    openGauss 2024-12-26 01:07:08
    cancel