/* ---------- * convert to ASCII - current enc is DatabaseEncoding * ---------- */ datum_t to_ascii_default(PG_FUNC_ARGS) { text *data = ARG_TEXT_P_COPY(0); int enc = get_db_encoding(); RET_TEXT_P(encode_to_ascii(data, enc)); }
/* ---------- * convert to ASCII - current enc is DatabaseEncoding * ---------- */ Datum to_ascii_default(PG_FUNCTION_ARGS) { text *data = PG_GETARG_TEXT_P_COPY(0); int enc = GetDatabaseEncoding(); PG_RETURN_TEXT_P(encode_to_ascii(data, enc)); }
/* ---------- * convert to ASCII - enc is set as int4 * ---------- */ Datum to_ascii_enc(PG_FUNCTION_ARGS) { text *data = PG_GETARG_TEXT_P_COPY(0); int enc = PG_GETARG_INT32(1); if (!PG_VALID_ENCODING(enc)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("%d is not a valid encoding code", enc))); PG_RETURN_TEXT_P(encode_to_ascii(data, enc)); }
/* ---------- * convert to ASCII - enc is set as int4 * ---------- */ datum_t to_ascii_enc(PG_FUNC_ARGS) { text *data = ARG_TEXT_P_COPY(0); int enc = ARG_INT32(1); if (!PG_VALID_ENC(enc)) { ereport(ERROR, ( errcode(E_UNDEFINED_OBJECT), errmsg("%d is not a valid encoding code", enc))); } RET_TEXT_P(encode_to_ascii(data, enc)); }
/* ---------- * convert to ASCII - enc is set as 'name' arg. * ---------- */ Datum to_ascii_encname(PG_FUNCTION_ARGS) { text *data = PG_GETARG_TEXT_P_COPY(0); char *encname = NameStr(*PG_GETARG_NAME(1)); int enc = pg_char_to_encoding(encname); if (enc < 0) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("%s is not a valid encoding name", encname))); PG_RETURN_TEXT_P(encode_to_ascii(data, enc)); }
/* ---------- * convert to ASCII - enc is set as 'name' arg. * ---------- */ datum_t to_ascii_encname(PG_FUNC_ARGS) { text *data = ARG_TEXT_P_COPY(0); char *encname = NAME_TO_STR(*ARG_NAME(1)); int enc = pg_char_to_encoding(encname); if (enc < 0) { ereport(ERROR, ( errcode(E_UNDEFINED_OBJECT), errmsg("%s is not a valid encoding name", encname))); } RET_TEXT_P(encode_to_ascii(data, enc)); }