/* must follow StdRdOptions conventions */ typedef struct BtOptions { int32 vl_len_; int fillfactor; char teststring[1]; } BtOptions; Datum btoptions(PG_FUNCTION_ARGS) { Datum reloptions = PG_GETARG_DATUM(0); bool validate = PG_GETARG_BOOL(1); bytea *result; relopt_value *options; int numoptions; int i; static bool initialized = false; if (!initialized) { add_string_reloption(RELOPT_KIND_BTREE, "teststring", NULL, "helluva string here and there!"); initialized = true; } options = parseRelOptions(reloptions, validate, RELOPT_KIND_BTREE, &numoptions); /* if none set, we're done */ if (numoptions == 0) result = NULL; else { BtOptions *rdopts; int tstrlen; for (i = 0; i < numoptions; i++) { if (HAVE_RELOPTION("teststring", options[i])) { tstrlen = options[i].isset ? strlen(options[i].values.string_val) : ((relopt_string *) options[i].gen)->default_len; break; } } rdopts = palloc0(sizeof(BtOptions) + tstrlen + 1); for (i = 0; i < numoptions; i++) { HANDLE_INT_RELOPTION("fillfactor", rdopts->fillfactor, options[i]); HANDLE_STRING_RELOPTION("teststring", rdopts->teststring, options[i]); } pfree(options); SET_VARSIZE(rdopts, sizeof(BtOptions) + tstrlen + 1); result = (bytea *) rdopts; } if (result) PG_RETURN_BYTEA_P(result); PG_RETURN_NULL(); }