MCPcopy Create free account
hub / github.com/apache/cloudberry / dbms_sql_define_column

Function dbms_sql_define_column

gpcontrib/orafce/dbms_sql.c:750–806  ·  view source on GitHub ↗

* CREATE PROCEDURE dbms_sql.define_column(c int, col int, value "any", column_size int DEFAULT -1); */

Source from the content-addressed store, hash-verified

748 * CREATE PROCEDURE dbms_sql.define_column(c int, col int, value "any", column_size int DEFAULT -1);
749 */
750Datum
751dbms_sql_define_column(PG_FUNCTION_ARGS)
752{
753 CursorData *c;
754 ColumnData *col;
755 Oid valtype;
756 Oid basetype;
757 int position;
758 int colsize;
759 TYPCATEGORY category;
760 bool ispreferred;
761
762 c = get_cursor(fcinfo, true);
763
764 if (PG_ARGISNULL(1))
765 ereport(ERROR,
766 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
767 errmsg("column position (number) is NULL")));
768
769 position = PG_GETARG_INT32(1);
770 col = get_col(c, position, true);
771
772 valtype = get_fn_expr_argtype(fcinfo->flinfo, 2);
773 if (valtype == RECORDOID)
774 ereport(ERROR,
775 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
776 errmsg("cannot to define a column of record type")));
777
778 if (valtype == UNKNOWNOID)
779 valtype = TEXTOID;
780
781 basetype = getBaseType(valtype);
782
783 if (col->typoid != InvalidOid)
784 ereport(ERROR,
785 (errcode(ERRCODE_DUPLICATE_COLUMN),
786 errmsg("column is defined already")));
787
788 col->typoid = valtype;
789
790 if (PG_ARGISNULL(3))
791 ereport(ERROR,
792 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
793 errmsg("column_size is NULL")));
794
795 colsize = PG_GETARG_INT32(3);
796
797 get_type_category_preferred(basetype, &category, &ispreferred);
798 col->typisstr = category == TYPCATEGORY_STRING;
799 col->typmod = (col->typisstr && colsize != -1) ? colsize + 4 : -1;
800
801 get_typlenbyval(basetype, &col->typlen, &col->typbyval);
802
803 col->rowcount = 1;
804
805 return (Datum) 0;
806}
807

Callers

nothing calls this directly

Calls 8

get_cursorFunction · 0.85
get_colFunction · 0.85
get_fn_expr_argtypeFunction · 0.85
getBaseTypeFunction · 0.85
get_typlenbyvalFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected