/* * oidvectorin - converts "num num ..." to internal form */ Datum oidvectorin(PG_FUNCTION_ARGS) { char *oidString = PG_GETARG_CSTRING(0); oidvector *result; int n; result = (oidvector *) palloc0(OidVectorSize(FUNC_MAX_ARGS)); for (n = 0; n < FUNC_MAX_ARGS; n++) { while (*oidString && isspace((unsigned char) *oidString)) oidString++; if (*oidString == '\0') break; result->values[n] = oidin_subr(oidString, &oidString); } while (*oidString && isspace((unsigned char) *oidString)) oidString++; if (*oidString) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("oidvector has too many elements"))); SET_VARSIZE(result, OidVectorSize(n)); result->ndim = 1; result->dataoffset = 0; /* never any nulls */ result->elemtype = OIDOID; result->dim1 = n; result->lbound1 = 0; PG_RETURN_POINTER(result); }
/* * oidvectorin - converts "num num ..." to internal form * * Note: * Fills any unsupplied positions with InvalidOid. */ Datum oidvectorin(PG_FUNCTION_ARGS) { char *oidString = PG_GETARG_CSTRING(0); Oid *result = (Oid *) palloc(sizeof(Oid[INDEX_MAX_KEYS])); int slot; for (slot = 0; slot < INDEX_MAX_KEYS; slot++) { while (*oidString && isspace((unsigned char) *oidString)) oidString++; if (*oidString == '\0') break; result[slot] = oidin_subr("oidvectorin", oidString, &oidString); } while (*oidString && isspace((unsigned char) *oidString)) oidString++; if (*oidString) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("oidvector has too many elements"))); while (slot < INDEX_MAX_KEYS) result[slot++] = InvalidOid; PG_RETURN_POINTER(result); }
Datum oidin(PG_FUNCTION_ARGS) { char *s = PG_GETARG_CSTRING(0); Oid result; result = oidin_subr(s, NULL); PG_RETURN_OID(result); }
/* * oidparse - get OID from IConst/FConst node */ Oid oidparse(Node *node) { switch (nodeTag(node)) { case T_Integer: return intVal(node); case T_Float: /* * Values too large for int4 will be represented as Float * constants by the lexer. Accept these if they are valid OID * strings. */ return oidin_subr(strVal(node), NULL); default: elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node)); } return InvalidOid; /* keep compiler quiet */ }
Datum text_oid(PG_FUNCTION_ARGS) { text *string = PG_GETARG_TEXT_P(0); Oid result; int len; char *str; len = (VARSIZE(string) - VARHDRSZ); str = palloc(len + 1); memcpy(str, VARDATA(string), len); *(str + len) = '\0'; result = oidin_subr("text_oid", str, NULL); pfree(str); PG_RETURN_OID(result); }