* CREATE PROCEDURE dbms_sql.define_array(c int, col int, value "anyarray", rowcount int, index1 int); */
| 809 | * CREATE PROCEDURE dbms_sql.define_array(c int, col int, value "anyarray", rowcount int, index1 int); |
| 810 | */ |
| 811 | Datum |
| 812 | dbms_sql_define_array(PG_FUNCTION_ARGS) |
| 813 | { |
| 814 | CursorData *c; |
| 815 | ColumnData *col; |
| 816 | Oid valtype; |
| 817 | Oid basetype; |
| 818 | int position; |
| 819 | int rowcount; |
| 820 | int index1; |
| 821 | Oid elementtype; |
| 822 | TYPCATEGORY category; |
| 823 | bool ispreferred; |
| 824 | |
| 825 | c = get_cursor(fcinfo, true); |
| 826 | |
| 827 | if (PG_ARGISNULL(1)) |
| 828 | ereport(ERROR, |
| 829 | (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
| 830 | errmsg("column position (number) is NULL"))); |
| 831 | |
| 832 | position = PG_GETARG_INT32(1); |
| 833 | col = get_col(c, position, true); |
| 834 | |
| 835 | valtype = get_fn_expr_argtype(fcinfo->flinfo, 2); |
| 836 | if (valtype == RECORDOID) |
| 837 | ereport(ERROR, |
| 838 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 839 | errmsg("cannot to define a column of record type"))); |
| 840 | |
| 841 | get_type_category_preferred(valtype, &category, &ispreferred); |
| 842 | if (category != TYPCATEGORY_ARRAY) |
| 843 | elog(ERROR, "defined value is not array"); |
| 844 | |
| 845 | col->typarrayoid = valtype; |
| 846 | |
| 847 | basetype = getBaseType(valtype); |
| 848 | elementtype = get_element_type(basetype); |
| 849 | |
| 850 | if (!OidIsValid(elementtype)) |
| 851 | ereport(ERROR, |
| 852 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 853 | errmsg("column is not a array"))); |
| 854 | |
| 855 | if (col->typoid != InvalidOid) |
| 856 | ereport(ERROR, |
| 857 | (errcode(ERRCODE_DUPLICATE_COLUMN), |
| 858 | errmsg("column is defined already"))); |
| 859 | |
| 860 | col->typoid = elementtype; |
| 861 | |
| 862 | if (PG_ARGISNULL(3)) |
| 863 | ereport(ERROR, |
| 864 | (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
| 865 | errmsg("cnt is NULL"))); |
| 866 | |
| 867 | rowcount = PG_GETARG_INT32(3); |
| 868 | if (rowcount <= 0) |
nothing calls this directly
no test coverage detected