PostgreSQL Source Code  git master
builtins.h File Reference
#include "fmgr.h"
#include "nodes/nodes.h"
#include "utils/fmgrprotos.h"
Include dependency graph for builtins.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAXINT8LEN   20
 
#define CStringGetTextDatum(s)   PointerGetDatum(cstring_to_text(s))
 
#define TextDatumGetCString(d)   text_to_cstring((text *) DatumGetPointer(d))
 
#define FORMAT_TYPE_TYPEMOD_GIVEN   0x01 /* typemod defined by caller */
 
#define FORMAT_TYPE_ALLOW_INVALID   0x02 /* allow invalid types */
 
#define FORMAT_TYPE_FORCE_QUALIFY   0x04 /* force qualification of type */
 

Functions

bool parse_bool (const char *value, bool *result)
 
bool parse_bool_with_len (const char *value, size_t len, bool *result)
 
void domain_check (Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt)
 
int errdatatype (Oid datatypeOid)
 
int errdomainconstraint (Oid datatypeOid, const char *conname)
 
unsigned hex_encode (const char *src, unsigned len, char *dst)
 
unsigned hex_decode (const char *src, unsigned len, char *dst)
 
int2vectorbuildint2vector (const int16 *int2s, int n)
 
int namecpy (Name n1, const NameData *n2)
 
int namestrcpy (Name name, const char *str)
 
int namestrcmp (Name name, const char *str)
 
int32 pg_atoi (const char *s, int size, int c)
 
int16 pg_strtoint16 (const char *s)
 
int32 pg_strtoint32 (const char *s)
 
void pg_itoa (int16 i, char *a)
 
int pg_ultoa_n (uint32 l, char *a)
 
int pg_ulltoa_n (uint64 l, char *a)
 
void pg_ltoa (int32 l, char *a)
 
void pg_lltoa (int64 ll, char *a)
 
char * pg_ultostr_zeropad (char *str, uint32 value, int32 minwidth)
 
char * pg_ultostr (char *str, uint32 value)
 
uint64 pg_strtouint64 (const char *str, char **endptr, int base)
 
oidvectorbuildoidvector (const Oid *oids, int n)
 
Oid oidparse (Node *node)
 
int oid_cmp (const void *p1, const void *p2)
 
char * regexp_fixed_prefix (text *text_re, bool case_insensitive, Oid collation, bool *exact)
 
const char * quote_identifier (const char *ident)
 
char * quote_qualified_identifier (const char *qualifier, const char *ident)
 
void generate_operator_clause (fmStringInfo buf, const char *leftop, Oid leftoptype, Oid opoid, const char *rightop, Oid rightoptype)
 
int bpchartruelen (char *s, int len)
 
textcstring_to_text (const char *s)
 
textcstring_to_text_with_len (const char *s, int len)
 
char * text_to_cstring (const text *t)
 
void text_to_cstring_buffer (const text *src, char *dst, size_t dst_len)
 
int xidComparator (const void *arg1, const void *arg2)
 
char * pg_inet_cidr_ntop (int af, const void *src, int bits, char *dst, size_t size)
 
int pg_inet_net_pton (int af, const char *src, void *dst, size_t size)
 
double convert_network_to_scalar (Datum value, Oid typid, bool *failure)
 
Datum network_scan_first (Datum in)
 
Datum network_scan_last (Datum in)
 
void clean_ipv6_addr (int addr_family, char *addr)
 
Datum numeric_float8_no_overflow (PG_FUNCTION_ARGS)
 
char * format_type_extended (Oid type_oid, int32 typemod, bits16 flags)
 
char * format_type_be (Oid type_oid)
 
char * format_type_be_qualified (Oid type_oid)
 
char * format_type_with_typemod (Oid type_oid, int32 typemod)
 
int32 type_maximum_size (Oid type_oid, int32 typemod)
 
char * quote_literal_cstr (const char *rawstr)
 

Variables

bool quote_all_identifiers
 

Macro Definition Documentation

◆ CStringGetTextDatum

#define CStringGetTextDatum (   s)    PointerGetDatum(cstring_to_text(s))

Definition at line 87 of file builtins.h.

Referenced by aclexplode(), AggregateCreate(), AlterCollation(), AlterDomainDefault(), AlterForeignServer(), AlterPolicy(), AlterRole(), AlterSubscription(), ApplyExtensionUpdates(), assign_text_var(), autoinc(), brin_metapage_info(), brin_page_items(), bt_page_print_tuples(), CollationCreate(), CreateComments(), CreateConstraintEntry(), CreateForeignServer(), CreatePolicy(), CreateReplicationSlot(), CreateRole(), CreateSharedComments(), CreateSubscription(), CreateTrigger(), dblink_get_connections(), dblink_get_notify(), deflist_to_tuplestore(), each_object_field_end(), elements_array_element_end(), exec_eval_using_params(), execute_extension_script(), extract_variadic_args(), fill_hba_line(), get_altertable_subcmdtypes(), get_available_versions_for_extension(), gethba_options(), GetSecurityLabel(), GetSharedSecurityLabel(), gin_page_opaque_info(), GUCArrayAdd(), heap_page_items(), heap_tuple_infomask_flags(), IdentifySystem(), insert_username(), InsertExtensionTuple(), InsertRule(), interpret_function_parameter_list(), json_object(), json_object_keys(), json_object_two_arg(), jsonb_object_keys(), page_header(), parse_ident(), pg_available_extensions(), pg_control_checkpoint(), pg_cursor(), pg_event_trigger_ddl_commands(), pg_event_trigger_dropped_objects(), pg_extension_update_paths(), pg_get_replication_slots(), pg_get_shmem_allocations(), pg_identify_object(), pg_identify_object_as_address(), pg_indexam_progress_phasename(), pg_listening_channels(), pg_lock_status(), pg_ls_dir(), pg_ls_dir_files(), pg_prepared_statement(), pg_prepared_xact(), pg_show_replication_origin_status(), pg_stat_get_activity(), pg_stat_get_archiver(), pg_stat_get_wal_receiver(), pg_stat_get_wal_senders(), pg_stat_statements_internal(), pg_stop_backup_v2(), pg_timezone_abbrevs(), pg_timezone_names(), pg_walfile_name_offset(), plpgsql_fulfill_promise(), ProcedureCreate(), publicationListToArray(), replorigin_by_name(), replorigin_create(), SetSecurityLabel(), SetSharedSecurityLabel(), ssl_extension_info(), StartReplication(), StoreAttrDefault(), StorePartitionBound(), StorePartitionKey(), string_to_datum(), strlist_to_textarray(), ts_lexize(), ttdummy(), TypeCreate(), UpdateIndexRelation(), and VXIDGetDatum().

◆ FORMAT_TYPE_ALLOW_INVALID

#define FORMAT_TYPE_ALLOW_INVALID   0x02 /* allow invalid types */

Definition at line 114 of file builtins.h.

Referenced by format_type(), format_type_extended(), and oidvectortypes().

◆ FORMAT_TYPE_FORCE_QUALIFY

#define FORMAT_TYPE_FORCE_QUALIFY   0x04 /* force qualification of type */

Definition at line 115 of file builtins.h.

Referenced by deparse_type_name(), format_type_be_qualified(), and format_type_extended().

◆ FORMAT_TYPE_TYPEMOD_GIVEN

#define FORMAT_TYPE_TYPEMOD_GIVEN   0x01 /* typemod defined by caller */

◆ MAXINT8LEN

#define MAXINT8LEN   20

Definition at line 22 of file builtins.h.

Referenced by int8out(), and printsimple().

◆ TextDatumGetCString

#define TextDatumGetCString (   d)    text_to_cstring((text *) DatumGetPointer(d))

Definition at line 88 of file builtins.h.

Referenced by AlterCollation(), AlterDomainValidateConstraint(), AlterPolicy(), AttrDefaultFetch(), binary_decode(), binary_encode(), binary_upgrade_create_empty_extension(), bpcharout(), build_function_result_tupdesc_d(), CheckConstraintFetch(), CloneRowTriggersToPartition(), compile_plperl_function(), compile_pltcl_function(), convert_string_datum(), DecodeTextArrayToBitmapset(), decompile_conbin(), DefineDomain(), do_compile(), DropSubscription(), exec_stmt_close(), exec_stmt_fetch(), exec_stmt_forc(), exec_stmt_open(), fetch_cursor_param_value(), fetch_function_defaults(), fetch_remote_table_info(), fetch_table_list(), fmgr_c_validator(), fmgr_info_C_lang(), fmgr_info_cxt_security(), fmgr_internal_validator(), fmgr_sql_validator(), fmgr_symbol(), func_get_detail(), generate_partition_qual(), generateClonedIndexStmt(), GenerateTypeDependencies(), get_func_arg_info(), get_func_input_arg_names(), get_func_result_name(), get_jsonb_path_all(), get_path_all(), get_qual_for_range(), get_reloptions(), get_role_password(), get_text_array_contents(), get_typdefault(), GetAggInitVal(), GetComment(), GetForeignServerExtended(), GetSecurityLabel(), GetSharedSecurityLabel(), GetSubscription(), GUCArrayAdd(), GUCArrayDelete(), GUCArrayReset(), index_concurrently_create_copy(), init_sql_fcache(), inline_function(), inline_set_returning_function(), json_object(), json_object_two_arg(), json_out(), jsonb_object(), jsonb_object_two_arg(), like_fixed_prefix(), load_domaintype_info(), make_greater_string(), MergeWithExistingConstraint(), metaphone(), parse_key_value_arrays(), parseRelOptionsInternal(), pg_get_constraintdef_worker(), pg_get_function_arg_default(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_object_address(), pg_get_partkeydef_worker(), pg_get_triggerdef_worker(), pg_logical_slot_get_changes_guts(), pg_newlocale_from_collation(), PLy_procedure_create(), print_function_arguments(), ProcedureCreate(), ProcessGUCArray(), regex_fixed_prefix(), RelationBuildPartitionDesc(), RelationBuildPartitionKey(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationBuildTriggers(), RelationGetDummyIndexExpressions(), RelationGetIndexAttrBitmap(), RelationGetIndexExpressions(), RelationGetIndexPredicate(), RemoveRoleFromObjectPolicy(), RenameRole(), sepgsql_restorecon(), sepgsql_setcon(), set_config_by_name(), setPathArray(), show_config_by_name(), show_config_by_name_missing_ok(), SPI_sql_row_to_xmlelement(), textarray_to_stringlist(), textarray_to_strvaluelist(), textout(), tfuncInitialize(), untransformRelOptions(), validateCheckConstraint(), and varcharout().

Function Documentation

◆ bpchartruelen()

int bpchartruelen ( char *  s,
int  len 
)

Definition at line 671 of file varchar.c.

References i.

Referenced by bcTruelen(), bpcharfastcmp_c(), varstr_abbrev_convert(), and varstrfastcmp_locale().

672 {
673  int i;
674 
675  /*
676  * Note that we rely on the assumption that ' ' is a singleton unit on
677  * every supported multibyte server encoding.
678  */
679  for (i = len - 1; i >= 0; i--)
680  {
681  if (s[i] != ' ')
682  break;
683  }
684  return i + 1;
685 }
int i

◆ buildint2vector()

int2vector* buildint2vector ( const int16 int2s,
int  n 
)

Definition at line 114 of file int.c.

References int2vector::dataoffset, int2vector::dim1, int2vector::elemtype, Int2VectorSize, int2vector::lbound1, int2vector::ndim, palloc0(), SET_VARSIZE, and int2vector::values.

Referenced by CreateStatistics(), CreateTrigger(), StorePartitionKey(), and UpdateIndexRelation().

115 {
116  int2vector *result;
117 
118  result = (int2vector *) palloc0(Int2VectorSize(n));
119 
120  if (n > 0 && int2s)
121  memcpy(result->values, int2s, n * sizeof(int16));
122 
123  /*
124  * Attach standard array header. For historical reasons, we set the index
125  * lower bound to 0 not 1.
126  */
127  SET_VARSIZE(result, Int2VectorSize(n));
128  result->ndim = 1;
129  result->dataoffset = 0; /* never any nulls */
130  result->elemtype = INT2OID;
131  result->dim1 = n;
132  result->lbound1 = 0;
133 
134  return result;
135 }
signed short int16
Definition: c.h:354
int lbound1
Definition: c.h:590
Oid elemtype
Definition: c.h:588
int32 dataoffset
Definition: c.h:587
int ndim
Definition: c.h:586
Definition: c.h:583
void * palloc0(Size size)
Definition: mcxt.c:980
int dim1
Definition: c.h:589
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:591
#define Int2VectorSize(n)
Definition: int.c:45
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329

◆ buildoidvector()

oidvector* buildoidvector ( const Oid oids,
int  n 
)

Definition at line 167 of file oid.c.

References oidvector::dataoffset, oidvector::dim1, oidvector::elemtype, oidvector::lbound1, oidvector::ndim, OidVectorSize, palloc0(), SET_VARSIZE, and oidvector::values.

Referenced by DefineAggregate(), interpret_function_parameter_list(), makeRangeConstructors(), StorePartitionKey(), and UpdateIndexRelation().

168 {
169  oidvector *result;
170 
171  result = (oidvector *) palloc0(OidVectorSize(n));
172 
173  if (n > 0 && oids)
174  memcpy(result->values, oids, n * sizeof(Oid));
175 
176  /*
177  * Attach standard array header. For historical reasons, we set the index
178  * lower bound to 0 not 1.
179  */
180  SET_VARSIZE(result, OidVectorSize(n));
181  result->ndim = 1;
182  result->dataoffset = 0; /* never any nulls */
183  result->elemtype = OIDOID;
184  result->dim1 = n;
185  result->lbound1 = 0;
186 
187  return result;
188 }
Definition: c.h:594
int32 dataoffset
Definition: c.h:598
unsigned int Oid
Definition: postgres_ext.h:31
#define OidVectorSize(n)
Definition: oid.c:27
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:602
int dim1
Definition: c.h:600
void * palloc0(Size size)
Definition: mcxt.c:980
int lbound1
Definition: c.h:601
Oid elemtype
Definition: c.h:599
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
int ndim
Definition: c.h:597

◆ clean_ipv6_addr()

void clean_ipv6_addr ( int  addr_family,
char *  addr 
)

Definition at line 2118 of file network.c.

Referenced by fill_hba_line(), inet_client_addr(), inet_server_addr(), pg_stat_get_activity(), and pg_stat_get_backend_client_addr().

2119 {
2120 #ifdef HAVE_IPV6
2121  if (addr_family == AF_INET6)
2122  {
2123  char *pct = strchr(addr, '%');
2124 
2125  if (pct)
2126  *pct = '\0';
2127  }
2128 #endif
2129 }

◆ convert_network_to_scalar()

double convert_network_to_scalar ( Datum  value,
Oid  typid,
bool failure 
)

Definition at line 1517 of file network.c.

References macaddr::a, macaddr8::a, macaddr::b, macaddr8::b, macaddr::c, macaddr8::c, macaddr::d, macaddr8::d, DatumGetInetPP, DatumGetMacaddr8P, DatumGetMacaddrP, macaddr::e, macaddr8::e, macaddr::f, macaddr8::f, macaddr8::g, macaddr8::h, i, ip_addr, ip_family, and PGSQL_AF_INET.

Referenced by convert_to_scalar(), gbt_inet_compress(), and gbt_inet_consistent().

1518 {
1519  switch (typid)
1520  {
1521  case INETOID:
1522  case CIDROID:
1523  {
1524  inet *ip = DatumGetInetPP(value);
1525  int len;
1526  double res;
1527  int i;
1528 
1529  /*
1530  * Note that we don't use the full address for IPv6.
1531  */
1532  if (ip_family(ip) == PGSQL_AF_INET)
1533  len = 4;
1534  else
1535  len = 5;
1536 
1537  res = ip_family(ip);
1538  for (i = 0; i < len; i++)
1539  {
1540  res *= 256;
1541  res += ip_addr(ip)[i];
1542  }
1543  return res;
1544  }
1545  case MACADDROID:
1546  {
1547  macaddr *mac = DatumGetMacaddrP(value);
1548  double res;
1549 
1550  res = (mac->a << 16) | (mac->b << 8) | (mac->c);
1551  res *= 256 * 256 * 256;
1552  res += (mac->d << 16) | (mac->e << 8) | (mac->f);
1553  return res;
1554  }
1555  case MACADDR8OID:
1556  {
1558  double res;
1559 
1560  res = (mac->a << 24) | (mac->b << 16) | (mac->c << 8) | (mac->d);
1561  res *= ((double) 256) * 256 * 256 * 256;
1562  res += (mac->e << 24) | (mac->f << 16) | (mac->g << 8) | (mac->h);
1563  return res;
1564  }
1565  }
1566 
1567  *failure = true;
1568  return 0;
1569 }
#define DatumGetMacaddrP(X)
Definition: inet.h:131
#define ip_family(inetptr)
Definition: inet.h:71
#define PGSQL_AF_INET
Definition: inet.h:39
#define DatumGetInetPP(X)
Definition: inet.h:122
unsigned char f
Definition: inet.h:101
#define ip_addr(inetptr)
Definition: inet.h:77
unsigned char h
Definition: inet.h:116
unsigned char f
Definition: inet.h:114
unsigned char g
Definition: inet.h:115
unsigned char c
Definition: inet.h:98
unsigned char a
Definition: inet.h:109
unsigned char a
Definition: inet.h:96
Definition: inet.h:107
unsigned char d
Definition: inet.h:99
unsigned char b
Definition: inet.h:110
Definition: inet.h:52
unsigned char e
Definition: inet.h:113
unsigned char c
Definition: inet.h:111
unsigned char b
Definition: inet.h:97
unsigned char e
Definition: inet.h:100
static struct @143 value
Definition: inet.h:94
#define DatumGetMacaddr8P(X)
Definition: inet.h:137
unsigned char d
Definition: inet.h:112
int i

◆ cstring_to_text()

text* cstring_to_text ( const char *  s)

Definition at line 172 of file varlena.c.

References cstring_to_text_with_len().

Referenced by array_dims(), ASN1_STRING_to_text(), booltext(), brin_page_type(), cash_words(), cidr_abbrev(), convert_charset(), cstring_to_xmltype(), current_query(), datetime_to_char_body(), dblink_build_sql_delete(), dblink_build_sql_insert(), dblink_build_sql_update(), dblink_cancel_query(), dblink_close(), dblink_connect(), dblink_disconnect(), dblink_error_message(), dblink_exec(), dblink_open(), dmetaphone(), dmetaphone_alt(), exec_assign_c_string(), executeDateTimeMethod(), filter_list_to_array(), format_type(), get_command_tag(), get_command_type(), get_jsonb_path_all(), get_scalar(), hash_page_type(), hstore_to_json(), hstore_to_json_loose(), inet_abbrev(), initcap(), json_in(), json_typeof(), jsonb_typeof(), JsonbValueAsText(), lower(), md5_bytea(), md5_text(), metaphone(), name_bpchar(), name_text(), network_host(), network_show(), oidvectortypes(), pg_collation_actual_version(), pg_collation_for(), pg_crypt(), pg_current_logfile(), pg_describe_object(), pg_export_snapshot(), pg_relation_filepath(), pg_size_pretty(), pg_size_pretty_numeric(), pg_stat_get_backend_activity(), pg_stat_get_backend_wait_event(), pg_stat_get_backend_wait_event_type(), pg_stat_get_slru(), pg_stats_ext_mcvlist_items(), pg_tablespace_location(), pg_walfile_name(), pgsql_version(), pgxml_result_to_text(), quote_ident(), quote_ident_cstr(), quote_nullable(), sepgsql_getcon(), sepgsql_mcstrans_in(), sepgsql_mcstrans_out(), set_config_by_name(), show_all_file_settings(), show_config_by_name(), show_config_by_name_missing_ok(), ShowAllGUCConfig(), soundex(), SPI_sql_row_to_xmlelement(), split_text(), ssl_cipher(), ssl_version(), string_to_text(), text_substring(), textin(), timeofday(), to_hex32(), to_hex64(), tsquerytree(), txid_status(), unaccent_dict(), upper(), X509_NAME_to_text(), xml_encode_special_chars(), xml_in(), and xml_recv().

173 {
174  return cstring_to_text_with_len(s, strlen(s));
175 }
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:184

◆ cstring_to_text_with_len()

text* cstring_to_text_with_len ( const char *  s,
int  len 
)

Definition at line 184 of file varlena.c.

References palloc(), SET_VARSIZE, VARDATA, and VARHDRSZ.

Referenced by array_to_json(), array_to_json_pretty(), array_to_text_internal(), build_regexp_match_result(), build_regexp_split_result(), compute_tsvector_stats(), concat_internal(), cstring_to_text(), cstring_to_xmltype(), do_text_output_multiline(), dotrim(), each_object_field_end(), each_worker_jsonb(), elements_array_element_end(), ExecEvalXmlExpr(), executeDateTimeMethod(), executeLikeRegex(), fsm_page_contents(), get_array_element_end(), get_array_end(), get_object_end(), get_object_field_end(), get_scalar(), gin_extract_tsquery(), gin_extract_tsvector(), hstore_akeys(), hstore_avals(), hstore_each(), hstore_fetchval(), hstore_skeys(), hstore_slice_to_array(), hstore_svals(), hstore_to_array_internal(), hstore_to_json(), hstore_to_json_loose(), json_build_array(), json_build_array_noargs(), json_build_object(), json_build_object_noargs(), json_object(), json_object_two_arg(), json_recv(), json_strip_nulls(), jsonb_pretty(), JsonbValueAsText(), leftmostvalue_text(), LogicalOutputWrite(), parse_ident(), pg_gen_salt(), pg_gen_salt_rounds(), replace_text(), replace_text_regexp(), row_to_json(), row_to_json_pretty(), serialize_deflist(), split_text(), ssl_extension_info(), string_agg_finalfn(), stringinfo_to_xmltype(), text_format(), text_left(), text_right(), text_to_array_internal(), textrecv(), to_json(), transform_json_string_values(), tsquerytree(), tsvector_to_array(), tsvector_unnest(), varchar(), varchar_input(), and xslt_process().

185 {
186  text *result = (text *) palloc(len + VARHDRSZ);
187 
188  SET_VARSIZE(result, len + VARHDRSZ);
189  memcpy(VARDATA(result), s, len);
190 
191  return result;
192 }
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARHDRSZ
Definition: c.h:561
void * palloc(Size size)
Definition: mcxt.c:949
Definition: c.h:555
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329

◆ domain_check()

void domain_check ( Datum  value,
bool  isnull,
Oid  domainType,
void **  extra,
MemoryContext  mcxt 
)

Definition at line 327 of file domains.c.

References CurrentMemoryContext, domain_check_input(), domain_state_setup(), and DomainIOData::domain_type.

Referenced by check_domain_for_new_field(), check_domain_for_new_tuple(), expanded_record_set_fields(), hstore_populate_record(), plperl_return_next_internal(), plperl_sv_to_datum(), plpgsql_exec_function(), pltcl_build_tuple_result(), PLyObject_ToDomain(), populate_composite(), populate_domain(), and populate_recordset_record().

329 {
330  DomainIOData *my_extra = NULL;
331 
332  if (mcxt == NULL)
333  mcxt = CurrentMemoryContext;
334 
335  /*
336  * We arrange to look up the needed info just once per series of calls,
337  * assuming the domain type doesn't change underneath us (which really
338  * shouldn't happen, but cope if it does).
339  */
340  if (extra)
341  my_extra = (DomainIOData *) *extra;
342  if (my_extra == NULL || my_extra->domain_type != domainType)
343  {
344  my_extra = domain_state_setup(domainType, true, mcxt);
345  if (extra)
346  *extra = (void *) my_extra;
347  }
348 
349  /*
350  * Do the necessary checks to ensure it's a valid domain value.
351  */
352  domain_check_input(value, isnull, my_extra);
353 }
Oid domain_type
Definition: domains.c:49
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
static struct @143 value
static DomainIOData * domain_state_setup(Oid domainType, bool binary, MemoryContext mcxt)
Definition: domains.c:73
static void domain_check_input(Datum value, bool isnull, DomainIOData *my_extra)
Definition: domains.c:131

◆ errdatatype()

int errdatatype ( Oid  datatypeOid)

Definition at line 360 of file domains.c.

References elog, err_generic_string(), ERROR, get_namespace_name(), GETSTRUCT, HeapTupleIsValid, NameStr, ObjectIdGetDatum, PG_DIAG_DATATYPE_NAME, PG_DIAG_SCHEMA_NAME, ReleaseSysCache(), SearchSysCache1(), and TYPEOID.

Referenced by domain_check_input(), errdomainconstraint(), and ExecEvalConstraintNotNull().

361 {
362  HeapTuple tup;
363  Form_pg_type typtup;
364 
365  tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(datatypeOid));
366  if (!HeapTupleIsValid(tup))
367  elog(ERROR, "cache lookup failed for type %u", datatypeOid);
368  typtup = (Form_pg_type) GETSTRUCT(tup);
369 
371  get_namespace_name(typtup->typnamespace));
373 
374  ReleaseSysCache(tup);
375 
376  return 0; /* return value does not matter */
377 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define PG_DIAG_SCHEMA_NAME
Definition: postgres_ext.h:65
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3155
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define PG_DIAG_DATATYPE_NAME
Definition: postgres_ext.h:68
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h:615
int err_generic_string(int field, const char *str)
Definition: elog.c:1265

◆ errdomainconstraint()

int errdomainconstraint ( Oid  datatypeOid,
const char *  conname 
)

Definition at line 384 of file domains.c.

References err_generic_string(), errdatatype(), and PG_DIAG_CONSTRAINT_NAME.

Referenced by domain_check_input(), and ExecEvalConstraintCheck().

385 {
386  errdatatype(datatypeOid);
388 
389  return 0; /* return value does not matter */
390 }
int errdatatype(Oid datatypeOid)
Definition: domains.c:360
#define PG_DIAG_CONSTRAINT_NAME
Definition: postgres_ext.h:69
int err_generic_string(int field, const char *str)
Definition: elog.c:1265

◆ format_type_be()

char* format_type_be ( Oid  type_oid)

Definition at line 327 of file format_type.c.

References format_type_extended().

Referenced by aclcheck_error_type(), addFamilyMember(), addRangeTableEntryForFunction(), AggregateCreate(), AlterType(), AlterTypeNamespace(), AlterTypeNamespace_oid(), AlterTypeNamespaceInternal(), AlterTypeOwner(), appendTypeNameToBuffer(), array_cat(), array_cmp(), array_contain_compare(), array_eq(), array_position_common(), array_positions(), array_recv(), array_replace_internal(), array_send(), assign_record_type_identifier(), ATAddForeignKeyConstraint(), ATExecAlterColumnType(), ATExecSetStorage(), ATPrepAlterColumnType(), brinvalidate(), btvalidate(), build_attrmap_by_name(), build_column_default(), build_datatype(), build_pertrans_for_aggref(), build_subplan(), CastCreate(), check_object_ownership(), check_of_type(), check_safe_enum_use(), check_sql_fn_retval(), check_valid_polymorphic_signature(), CheckAttributeType(), checkDomainOwner(), checkEnumOwner(), checkRuleResultList(), CheckVarSlotCompatibility(), coerce_record_to_complex(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), coerce_type(), compare_values_of_enum(), compile_plperl_function(), compile_pltcl_function(), ComputeIndexAttrs(), ComputePartitionAttrs(), cookDefault(), create_ctas_nodata(), CreateCast(), CreateFunction(), CreateStatistics(), CreateTransform(), DefineAggregate(), DefineDomain(), DefineRange(), DefineType(), do_compile(), domain_check_input(), domain_state_setup(), dropOperators(), dropProcedures(), enforce_generic_type_consistency(), enum_first(), enum_in(), enum_last(), enum_recv(), EvaluateParams(), exec_stmt_foreach_a(), ExecCheckPlanOutput(), ExecEvalArrayExpr(), ExecEvalConstraintCheck(), ExecEvalConstraintNotNull(), ExecEvalFieldSelect(), ExecEvalParamExtern(), ExecEvalWholeRowVar(), ExecInitExprRec(), exprType(), fetch_cursor_param_value(), findRangeSubOpclass(), findTypeInputFunction(), findTypeReceiveFunction(), fmgr_sql_validator(), format_operator_internal(), format_procedure_internal(), funcname_signature_string(), get_cast_oid(), get_domain_constraint_oid(), get_expr_result_tupdesc(), get_range_io_data(), get_rels_with_domain(), get_sort_group_operators(), get_transform_oid(), get_ts_parser_func(), get_ts_template_func(), GetColumnDefCollation(), GetDefaultOpClass(), getObjectDescription(), getTypeBinaryInputInfo(), getTypeBinaryOutputInfo(), getTypeInputInfo(), getTypeOutputInfo(), hash_array(), hash_array_extended(), hash_range(), hash_range_extended(), hashvalidate(), init_params(), initArrayResultArr(), initGinState(), internal_get_result_type(), intorel_startup(), load_enum_cache_data(), logicalrep_typmap_gettypname(), lookup_rowtype_tupdesc_domain(), lookup_rowtype_tupdesc_internal(), LookupTypeNameExtended(), make_expanded_record_from_tupdesc(), make_expanded_record_from_typeid(), make_row_comparison_op(), make_scalar_array_op(), op_signature_string(), ParseFuncOrColumn(), pg_collation_for(), plperl_array_to_datum(), plperl_sv_to_datum(), plperl_validator(), plpgsql_build_variable(), plpgsql_param_eval_generic(), plpgsql_param_eval_generic_ro(), plpgsql_param_eval_recfield(), plpgsql_validator(), PLy_procedure_create(), prepare_sql_fn_parse_info(), print_function_arguments(), print_function_rettype(), print_function_trftypes(), processIndirection(), record_cmp(), record_eq(), record_image_cmp(), record_image_eq(), regtypeout(), RelationBuildPartitionKey(), RenameConstraintById(), RenameType(), resolve_anyarray_from_others(), resolve_anyelement_from_others(), ResolveOpClass(), revalidate_rectypeid(), ri_HashCompareOp(), satisfies_hash_partition(), select_common_type(), select_common_type_from_oids(), slot_store_error_callback(), spgvalidate(), storeOperators(), storeProcedures(), transformAggregateCall(), transformArrayExpr(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformCollateClause(), transformColumnType(), transformContainerSubscripts(), transformContainerType(), transformFrameOffset(), transformPartitionBoundValue(), transformTypeCast(), transformXmlSerialize(), tuple_to_stringinfo(), tupledesc_match(), tuples_equal(), unknown_attribute(), validateConnectbyTupleDesc(), variable_coerce_param_hook(), and width_bucket_array().

328 {
329  return format_type_extended(type_oid, -1, 0);
330 }
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
Definition: format_type.c:108

◆ format_type_be_qualified()

char* format_type_be_qualified ( Oid  type_oid)

Definition at line 337 of file format_type.c.

References format_type_extended(), and FORMAT_TYPE_FORCE_QUALIFY.

Referenced by format_operator_internal(), format_operator_parts(), format_procedure_internal(), format_procedure_parts(), and getObjectIdentityParts().

338 {
339  return format_type_extended(type_oid, -1, FORMAT_TYPE_FORCE_QUALIFY);
340 }
#define FORMAT_TYPE_FORCE_QUALIFY
Definition: builtins.h:115
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
Definition: format_type.c:108

◆ format_type_extended()

char* format_type_extended ( Oid  type_oid,
int32  typemod,
bits16  flags 
)

Definition at line 108 of file format_type.c.

References buf, elog, ERROR, FORMAT_TYPE_ALLOW_INVALID, FORMAT_TYPE_FORCE_QUALIFY, FORMAT_TYPE_TYPEMOD_GIVEN, get_namespace_name_or_temp(), GETSTRUCT, HeapTupleIsValid, InvalidOid, NameStr, ObjectIdGetDatum, printTypmod(), psprintf(), pstrdup(), quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), TypeIsVisible(), TYPEOID, and typname.

Referenced by deparse_type_name(), format_type(), format_type_be(), format_type_be_qualified(), format_type_with_typemod(), lookup_am_handler_func(), and oidvectortypes().

109 {
110  HeapTuple tuple;
111  Form_pg_type typeform;
112  Oid array_base_type;
113  bool is_array;
114  char *buf;
115  bool with_typemod;
116 
117  if (type_oid == InvalidOid && (flags & FORMAT_TYPE_ALLOW_INVALID) != 0)
118  return pstrdup("-");
119 
120  tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_oid));
121  if (!HeapTupleIsValid(tuple))
122  {
123  if ((flags & FORMAT_TYPE_ALLOW_INVALID) != 0)
124  return pstrdup("???");
125  else
126  elog(ERROR, "cache lookup failed for type %u", type_oid);
127  }
128  typeform = (Form_pg_type) GETSTRUCT(tuple);
129 
130  /*
131  * Check if it's a regular (variable length) array type. Fixed-length
132  * array types such as "name" shouldn't get deconstructed. As of Postgres
133  * 8.1, rather than checking typlen we check the toast property, and don't
134  * deconstruct "plain storage" array types --- this is because we don't
135  * want to show oidvector as oid[].
136  */
137  array_base_type = typeform->typelem;
138 
139  if (array_base_type != InvalidOid &&
140  typeform->typstorage != TYPSTORAGE_PLAIN)
141  {
142  /* Switch our attention to the array element type */
143  ReleaseSysCache(tuple);
144  tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(array_base_type));
145  if (!HeapTupleIsValid(tuple))
146  {
147  if ((flags & FORMAT_TYPE_ALLOW_INVALID) != 0)
148  return pstrdup("???[]");
149  else
150  elog(ERROR, "cache lookup failed for type %u", type_oid);
151  }
152  typeform = (Form_pg_type) GETSTRUCT(tuple);
153  type_oid = array_base_type;
154  is_array = true;
155  }
156  else
157  is_array = false;
158 
159  with_typemod = (flags & FORMAT_TYPE_TYPEMOD_GIVEN) != 0 && (typemod >= 0);
160 
161  /*
162  * See if we want to special-case the output for certain built-in types.
163  * Note that these special cases should all correspond to special
164  * productions in gram.y, to ensure that the type name will be taken as a
165  * system type, not a user type of the same name.
166  *
167  * If we do not provide a special-case output here, the type name will be
168  * handled the same way as a user type name --- in particular, it will be
169  * double-quoted if it matches any lexer keyword. This behavior is
170  * essential for some cases, such as types "bit" and "char".
171  */
172  buf = NULL; /* flag for no special case */
173 
174  switch (type_oid)
175  {
176  case BITOID:
177  if (with_typemod)
178  buf = printTypmod("bit", typemod, typeform->typmodout);
179  else if ((flags & FORMAT_TYPE_TYPEMOD_GIVEN) != 0)
180  {
181  /*
182  * bit with typmod -1 is not the same as BIT, which means
183  * BIT(1) per SQL spec. Report it as the quoted typename so
184  * that parser will not assign a bogus typmod.
185  */
186  }
187  else
188  buf = pstrdup("bit");
189  break;
190 
191  case BOOLOID:
192  buf = pstrdup("boolean");
193  break;
194 
195  case BPCHAROID:
196  if (with_typemod)
197  buf = printTypmod("character", typemod, typeform->typmodout);
198  else if ((flags & FORMAT_TYPE_TYPEMOD_GIVEN) != 0)
199  {
200  /*
201  * bpchar with typmod -1 is not the same as CHARACTER, which
202  * means CHARACTER(1) per SQL spec. Report it as bpchar so
203  * that parser will not assign a bogus typmod.
204  */
205  }
206  else
207  buf = pstrdup("character");
208  break;
209 
210  case FLOAT4OID:
211  buf = pstrdup("real");
212  break;
213 
214  case FLOAT8OID:
215  buf = pstrdup("double precision");
216  break;
217 
218  case INT2OID:
219  buf = pstrdup("smallint");
220  break;
221 
222  case INT4OID:
223  buf = pstrdup("integer");
224  break;
225 
226  case INT8OID:
227  buf = pstrdup("bigint");
228  break;
229 
230  case NUMERICOID:
231  if (with_typemod)
232  buf = printTypmod("numeric", typemod, typeform->typmodout);
233  else
234  buf = pstrdup("numeric");
235  break;
236 
237  case INTERVALOID:
238  if (with_typemod)
239  buf = printTypmod("interval", typemod, typeform->typmodout);
240  else
241  buf = pstrdup("interval");
242  break;
243 
244  case TIMEOID:
245  if (with_typemod)
246  buf = printTypmod("time", typemod, typeform->typmodout);
247  else
248  buf = pstrdup("time without time zone");
249  break;
250 
251  case TIMETZOID:
252  if (with_typemod)
253  buf = printTypmod("time", typemod, typeform->typmodout);
254  else
255  buf = pstrdup("time with time zone");
256  break;
257 
258  case TIMESTAMPOID:
259  if (with_typemod)
260  buf = printTypmod("timestamp", typemod, typeform->typmodout);
261  else
262  buf = pstrdup("timestamp without time zone");
263  break;
264 
265  case TIMESTAMPTZOID:
266  if (with_typemod)
267  buf = printTypmod("timestamp", typemod, typeform->typmodout);
268  else
269  buf = pstrdup("timestamp with time zone");
270  break;
271 
272  case VARBITOID:
273  if (with_typemod)
274  buf = printTypmod("bit varying", typemod, typeform->typmodout);
275  else
276  buf = pstrdup("bit varying");
277  break;
278 
279  case VARCHAROID:
280  if (with_typemod)
281  buf = printTypmod("character varying", typemod, typeform->typmodout);
282  else
283  buf = pstrdup("character varying");
284  break;
285  }
286 
287  if (buf == NULL)
288  {
289  /*
290  * Default handling: report the name as it appears in the catalog.
291  * Here, we must qualify the name if it is not visible in the search
292  * path or if caller requests it; and we must double-quote it if it's
293  * not a standard identifier or if it matches any keyword.
294  */
295  char *nspname;
296  char *typname;
297 
298  if ((flags & FORMAT_TYPE_FORCE_QUALIFY) == 0 &&
299  TypeIsVisible(type_oid))
300  nspname = NULL;
301  else
302  nspname = get_namespace_name_or_temp(typeform->typnamespace);
303 
304  typname = NameStr(typeform->typname);
305 
306  buf = quote_qualified_identifier(nspname, typname);
307 
308  if (with_typemod)
309  buf = printTypmod(buf, typemod, typeform->typmodout);
310  }
311 
312  if (is_array)
313  buf = psprintf("%s[]", buf);
314 
315  ReleaseSysCache(tuple);
316 
317  return buf;
318 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1186
#define FORMAT_TYPE_TYPEMOD_GIVEN
Definition: builtins.h:113
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:67
#define FORMAT_TYPE_FORCE_QUALIFY
Definition: builtins.h:115
NameData typname
Definition: pg_type.h:41
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10808
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
#define FORMAT_TYPE_ALLOW_INVALID
Definition: builtins.h:114
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
bool TypeIsVisible(Oid typid)
Definition: namespace.c:816
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
static char * printTypmod(const char *typname, int32 typmod, Oid typmodout)
Definition: format_type.c:355
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3179
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h:615

◆ format_type_with_typemod()

char* format_type_with_typemod ( Oid  type_oid,
int32  typemod 
)

◆ generate_operator_clause()

void generate_operator_clause ( fmStringInfo  buf,
const char *  leftop,
Oid  leftoptype,
Oid  opoid,
const char *  rightop,
Oid  rightoptype 
)

Definition at line 11136 of file ruleutils.c.

References add_cast_to(), appendStringInfo(), appendStringInfoString(), Assert, elog, ERROR, get_namespace_name(), GETSTRUCT, HeapTupleIsValid, NameStr, ObjectIdGetDatum, OPEROID, quote_identifier(), ReleaseSysCache(), and SearchSysCache1().

Referenced by refresh_by_match_merge(), and ri_GenerateQual().

11140 {
11141  HeapTuple opertup;
11142  Form_pg_operator operform;
11143  char *oprname;
11144  char *nspname;
11145 
11146  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(opoid));
11147  if (!HeapTupleIsValid(opertup))
11148  elog(ERROR, "cache lookup failed for operator %u", opoid);
11149  operform = (Form_pg_operator) GETSTRUCT(opertup);
11150  Assert(operform->oprkind == 'b');
11151  oprname = NameStr(operform->oprname);
11152 
11153  nspname = get_namespace_name(operform->oprnamespace);
11154 
11155  appendStringInfoString(buf, leftop);
11156  if (leftoptype != operform->oprleft)
11157  add_cast_to(buf, operform->oprleft);
11158  appendStringInfo(buf, " OPERATOR(%s.", quote_identifier(nspname));
11159  appendStringInfoString(buf, oprname);
11160  appendStringInfo(buf, ") %s", rightop);
11161  if (rightoptype != operform->oprright)
11162  add_cast_to(buf, operform->oprright);
11163 
11164  ReleaseSysCache(opertup);
11165 }
static void add_cast_to(StringInfo buf, Oid typid)
Definition: ruleutils.c:11176
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10724
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3155
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:738
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
#define elog(elevel,...)
Definition: elog.h:214
#define NameStr(name)
Definition: c.h:615

◆ hex_decode()

unsigned hex_decode ( const char *  src,
unsigned  len,
char *  dst 
)

Definition at line 156 of file encode.c.

References ereport, errcode(), errmsg(), ERROR, and get_hex().

Referenced by byteain().

157 {
158  const char *s,
159  *srcend;
160  char v1,
161  v2,
162  *p;
163 
164  srcend = src + len;
165  s = src;
166  p = dst;
167  while (s < srcend)
168  {
169  if (*s == ' ' || *s == '\n' || *s == '\t' || *s == '\r')
170  {
171  s++;
172  continue;
173  }
174  v1 = get_hex(*s++) << 4;
175  if (s >= srcend)
176  ereport(ERROR,
177  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
178  errmsg("invalid hexadecimal data: odd number of digits")));
179 
180  v2 = get_hex(*s++);
181  *p++ = v1 | v2;
182  }
183 
184  return p - dst;
185 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
static char get_hex(char c)
Definition: encode.c:140
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ hex_encode()

unsigned hex_encode ( const char *  src,
unsigned  len,
char *  dst 
)

Definition at line 126 of file encode.c.

References hextbl.

Referenced by AddFileToManifest(), byteaout(), and SendBackupManifest().

127 {
128  const char *end = src + len;
129 
130  while (src < end)
131  {
132  *dst++ = hextbl[(*src >> 4) & 0xF];
133  *dst++ = hextbl[*src & 0xF];
134  src++;
135  }
136  return len * 2;
137 }
static const char hextbl[]
Definition: encode.c:112

◆ namecpy()

int namecpy ( Name  n1,
const NameData n2 
)

Definition at line 233 of file name.c.

References NAMEDATALEN, NameStr, and StrNCpy.

Referenced by pg_get_replication_slots().

234 {
235  if (!n1 || !n2)
236  return -1;
237  StrNCpy(NameStr(*n1), NameStr(*n2), NAMEDATALEN);
238  return 0;
239 }
#define NAMEDATALEN
#define StrNCpy(dst, src, len)
Definition: c.h:944
#define NameStr(name)
Definition: c.h:615

◆ namestrcmp()

int namestrcmp ( Name  name,
const char *  str 
)

Definition at line 287 of file name.c.

References NAMEDATALEN, and NameStr.

Referenced by attnameAttNum(), CopyGetAttnums(), CreateTrigger(), expanded_record_lookup_field(), GetAttributeByName(), and SPI_fnumber().

288 {
289  if (!name && !str)
290  return 0;
291  if (!name)
292  return -1; /* NULL < anything */
293  if (!str)
294  return 1; /* NULL < anything */
295  return strncmp(NameStr(*name), str, NAMEDATALEN);
296 }
#define NAMEDATALEN
#define NameStr(name)
Definition: c.h:615

◆ namestrcpy()

int namestrcpy ( Name  name,
const char *  str 
)

◆ network_scan_first()

Datum network_scan_first ( Datum  in)

Definition at line 1705 of file network.c.

References DirectFunctionCall1, and network_network().

Referenced by match_network_subset().

1706 {
1708 }
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
Datum network_network(PG_FUNCTION_ARGS)
Definition: network.c:1345

◆ network_scan_last()

Datum network_scan_last ( Datum  in)

Definition at line 1719 of file network.c.

References DirectFunctionCall1, DirectFunctionCall2, inet_set_masklen(), Int32GetDatum, and network_broadcast().

Referenced by match_network_subset().

1720 {
1723  Int32GetDatum(-1));
1724 }
Datum network_broadcast(PG_FUNCTION_ARGS)
Definition: network.c:1300
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:619
Datum inet_set_masklen(PG_FUNCTION_ARGS)
Definition: network.c:325
#define Int32GetDatum(X)
Definition: postgres.h:479
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:621

◆ numeric_float8_no_overflow()

Datum numeric_float8_no_overflow ( PG_FUNCTION_ARGS  )

Definition at line 3626 of file numeric.c.

References get_float8_nan(), NUMERIC_IS_NAN, numeric_to_double_no_overflow(), PG_GETARG_NUMERIC, PG_RETURN_FLOAT8, and val.

Referenced by convert_numeric_to_scalar(), and gbt_numeric_penalty().

3627 {
3628  Numeric num = PG_GETARG_NUMERIC(0);
3629  double val;
3630 
3631  if (NUMERIC_IS_NAN(num))
3633 
3634  val = numeric_to_double_no_overflow(num);
3635 
3636  PG_RETURN_FLOAT8(val);
3637 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:360
static float8 get_float8_nan(void)
Definition: float.h:122
#define PG_GETARG_NUMERIC(n)
Definition: numeric.h:52
static double numeric_to_double_no_overflow(Numeric num)
Definition: numeric.c:6866
#define NUMERIC_IS_NAN(n)
Definition: numeric.c:173
long val
Definition: informix.c:664

◆ oid_cmp()

int oid_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 336 of file oid.c.

Referenced by aclmembers(), AlterSubscription_refresh(), EnumValuesCreate(), and find_inheritance_children().

337 {
338  Oid v1 = *((const Oid *) p1);
339  Oid v2 = *((const Oid *) p2);
340 
341  if (v1 < v2)
342  return -1;
343  if (v1 > v2)
344  return 1;
345  return 0;
346 }
unsigned int Oid
Definition: postgres_ext.h:31

◆ oidparse()

Oid oidparse ( Node node)

Definition at line 314 of file oid.c.

References elog, ERROR, intVal, InvalidOid, nodeTag, oidin_subr(), strVal, T_Float, and T_Integer.

Referenced by get_object_address(), and objectNamesToOids().

315 {
316  switch (nodeTag(node))
317  {
318  case T_Integer:
319  return intVal(node);
320  case T_Float:
321 
322  /*
323  * Values too large for int4 will be represented as Float
324  * constants by the lexer. Accept these if they are valid OID
325  * strings.
326  */
327  return oidin_subr(strVal(node), NULL);
328  default:
329  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
330  }
331  return InvalidOid; /* keep compiler quiet */
332 }
static Oid oidin_subr(const char *s, char **endloc)
Definition: oid.c:35
#define strVal(v)
Definition: value.h:54
#define ERROR
Definition: elog.h:43
#define InvalidOid
Definition: postgres_ext.h:36
#define nodeTag(nodeptr)
Definition: nodes.h:531
Definition: nodes.h:289
#define intVal(v)
Definition: value.h:52
#define elog(elevel,...)
Definition: elog.h:214

◆ parse_bool()

bool parse_bool ( const char *  value,
bool result 
)

Definition at line 30 of file bool.c.

References parse_bool_with_len().

Referenced by parse_and_validate_value(), parse_basebackup_options(), parse_extension_control_file(), parse_one_reloption(), pg_decode_startup(), and ProcessStartupPacket().

31 {
32  return parse_bool_with_len(value, strlen(value), result);
33 }
bool parse_bool_with_len(const char *value, size_t len, bool *result)
Definition: bool.c:36
static struct @143 value

◆ parse_bool_with_len()

bool parse_bool_with_len ( const char *  value,
size_t  len,
bool result 
)

Definition at line 36 of file bool.c.

References pg_strncasecmp().

Referenced by boolin(), and parse_bool().

37 {
38  switch (*value)
39  {
40  case 't':
41  case 'T':
42  if (pg_strncasecmp(value, "true", len) == 0)
43  {
44  if (result)
45  *result = true;
46  return true;
47  }
48  break;
49  case 'f':
50  case 'F':
51  if (pg_strncasecmp(value, "false", len) == 0)
52  {
53  if (result)
54  *result = false;
55  return true;
56  }
57  break;
58  case 'y':
59  case 'Y':
60  if (pg_strncasecmp(value, "yes", len) == 0)
61  {
62  if (result)
63  *result = true;
64  return true;
65  }
66  break;
67  case 'n':
68  case 'N':
69  if (pg_strncasecmp(value, "no", len) == 0)
70  {
71  if (result)
72  *result = false;
73  return true;
74  }
75  break;
76  case 'o':
77  case 'O':
78  /* 'o' is not unique enough */
79  if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
80  {
81  if (result)
82  *result = true;
83  return true;
84  }
85  else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
86  {
87  if (result)
88  *result = false;
89  return true;
90  }
91  break;
92  case '1':
93  if (len == 1)
94  {
95  if (result)
96  *result = true;
97  return true;
98  }
99  break;
100  case '0':
101  if (len == 1)
102  {
103  if (result)
104  *result = false;
105  return true;
106  }
107  break;
108  default:
109  break;
110  }
111 
112  if (result)
113  *result = false; /* suppress compiler warning */
114  return false;
115 }
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
static struct @143 value

◆ pg_atoi()

int32 pg_atoi ( const char *  s,
int  size,
int  c 
)

Definition at line 100 of file numutils.c.

References elog, ereport, errcode(), errmsg(), and ERROR.

Referenced by int2vectorin().

101 {
102  long l;
103  char *badp;
104 
105  /*
106  * Some versions of strtol treat the empty string as an error, but some
107  * seem not to. Make an explicit test to be sure we catch it.
108  */
109  if (s == NULL)
110  elog(ERROR, "NULL pointer");
111  if (*s == 0)
112  ereport(ERROR,
113  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
114  errmsg("invalid input syntax for type %s: \"%s\"",
115  "integer", s)));
116 
117  errno = 0;
118  l = strtol(s, &badp, 10);
119 
120  /* We made no progress parsing the string, so bail out */
121  if (s == badp)
122  ereport(ERROR,
123  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
124  errmsg("invalid input syntax for type %s: \"%s\"",
125  "integer", s)));
126 
127  switch (size)
128  {
129  case sizeof(int32):
130  if (errno == ERANGE
131 #if defined(HAVE_LONG_INT_64)
132  /* won't get ERANGE on these with 64-bit longs... */
133  || l < INT_MIN || l > INT_MAX
134 #endif
135  )
136  ereport(ERROR,
137  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
138  errmsg("value \"%s\" is out of range for type %s", s,
139  "integer")));
140  break;
141  case sizeof(int16):
142  if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX)
143  ereport(ERROR,
144  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
145  errmsg("value \"%s\" is out of range for type %s", s,
146  "smallint")));
147  break;
148  case sizeof(int8):
149  if (errno == ERANGE || l < SCHAR_MIN || l > SCHAR_MAX)
150  ereport(ERROR,
151  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
152  errmsg("value \"%s\" is out of range for 8-bit integer", s)));
153  break;
154  default:
155  elog(ERROR, "unsupported result size: %d", size);
156  }
157 
158  /*
159  * Skip any trailing whitespace; if anything but whitespace remains before
160  * the terminating character, bail out
161  */
162  while (*badp && *badp != c && isspace((unsigned char) *badp))
163  badp++;
164 
165  if (*badp && *badp != c)
166  ereport(ERROR,
167  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
168  errmsg("invalid input syntax for type %s: \"%s\"",
169  "integer", s)));
170 
171  return (int32) l;
172 }
signed short int16
Definition: c.h:354
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
char * c
signed char int8
Definition: c.h:353
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214

◆ pg_inet_cidr_ntop()

char* pg_inet_cidr_ntop ( int  af,
const void *  src,
int  bits,
char *  dst,
size_t  size 
)

Definition at line 56 of file inet_cidr_ntop.c.

References EAFNOSUPPORT, inet_cidr_ntop_ipv4(), inet_cidr_ntop_ipv6(), PGSQL_AF_INET, and PGSQL_AF_INET6.

Referenced by cidr_abbrev().

57 {
58  switch (af)
59  {
60  case PGSQL_AF_INET:
61  return inet_cidr_ntop_ipv4(src, bits, dst, size);
62  case PGSQL_AF_INET6:
63  return inet_cidr_ntop_ipv6(src, bits, dst, size);
64  default:
65  errno = EAFNOSUPPORT;
66  return NULL;
67  }
68 }
#define PGSQL_AF_INET
Definition: inet.h:39
static char * inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
#define PGSQL_AF_INET6
Definition: inet.h:40
static char * inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
#define EAFNOSUPPORT
Definition: win32_port.h:327

◆ pg_inet_net_pton()

int pg_inet_net_pton ( int  af,
const char *  src,
void *  dst,
size_t  size 
)

Definition at line 62 of file inet_net_pton.c.

References EAFNOSUPPORT, inet_cidr_pton_ipv4(), inet_cidr_pton_ipv6(), inet_net_pton_ipv4(), inet_net_pton_ipv6(), PGSQL_AF_INET, and PGSQL_AF_INET6.

Referenced by network_in().

63 {
64  switch (af)
65  {
66  case PGSQL_AF_INET:
67  return size == -1 ?
68  inet_net_pton_ipv4(src, dst) :
69  inet_cidr_pton_ipv4(src, dst, size);
70  case PGSQL_AF_INET6:
71  return size == -1 ?
72  inet_net_pton_ipv6(src, dst) :
73  inet_cidr_pton_ipv6(src, dst, size);
74  default:
75  errno = EAFNOSUPPORT;
76  return -1;
77  }
78 }
static int inet_net_pton_ipv6(const char *src, u_char *dst)
#define PGSQL_AF_INET
Definition: inet.h:39
#define PGSQL_AF_INET6
Definition: inet.h:40
static int inet_cidr_pton_ipv4(const char *src, u_char *dst, size_t size)
Definition: inet_net_pton.c:97
#define EAFNOSUPPORT
Definition: win32_port.h:327
static int inet_net_pton_ipv4(const char *src, u_char *dst)
static int inet_cidr_pton_ipv6(const char *src, u_char *dst, size_t size)

◆ pg_itoa()

void pg_itoa ( int16  i,
char *  a 
)

Definition at line 335 of file numutils.c.

References pg_ltoa().

Referenced by int2out(), int2vectorout(), LogicalTapeSetCreate(), and ltsConcatWorkerTapes().

336 {
337  pg_ltoa((int32) i, a);
338 }
signed int int32
Definition: c.h:355
int i
void pg_ltoa(int32 value, char *a)
Definition: numutils.c:412

◆ pg_lltoa()

void pg_lltoa ( int64  ll,
char *  a 
)

Definition at line 519 of file numutils.c.

References pg_ulltoa_n(), and value.

Referenced by int8out(), and printsimple().

520 {
521  int len;
522  uint64 uvalue = value;
523 
524  if (value < 0)
525  {
526  *a++ = '-';
527  uvalue = (uint64) 0 - uvalue;
528  }
529  len = pg_ulltoa_n(uvalue, a);
530  a[len] = 0;
531 }
int pg_ulltoa_n(uint64 value, char *a)
Definition: numutils.c:432
static struct @143 value

◆ pg_ltoa()

void pg_ltoa ( int32  l,
char *  a 
)

Definition at line 412 of file numutils.c.

References pg_ultoa_n().

Referenced by int4out(), pg_itoa(), and printsimple().

413 {
414 
415  uint32 uvalue = (uint32) value;
416  int len;
417 
418  if (value < 0)
419  {
420  uvalue = (uint32) 0 - uvalue;
421  *a++ = '-';
422  }
423  len = pg_ultoa_n(uvalue, a);
424  a[len] = '\0';
425 }
unsigned int uint32
Definition: c.h:367
static struct @143 value
int pg_ultoa_n(uint32 value, char *a)
Definition: numutils.c:348

◆ pg_strtoint16()

int16 pg_strtoint16 ( const char *  s)

Definition at line 185 of file numutils.c.

References ereport, errcode(), errmsg(), ERROR, likely, PG_INT16_MIN, pg_mul_s16_overflow(), pg_sub_s16_overflow(), and unlikely.

Referenced by int2in().

186 {
187  const char *ptr = s;
188  int16 tmp = 0;
189  bool neg = false;
190 
191  /* skip leading spaces */
192  while (likely(*ptr) && isspace((unsigned char) *ptr))
193  ptr++;
194 
195  /* handle sign */
196  if (*ptr == '-')
197  {
198  ptr++;
199  neg = true;
200  }
201  else if (*ptr == '+')
202  ptr++;
203 
204  /* require at least one digit */
205  if (unlikely(!isdigit((unsigned char) *ptr)))
206  goto invalid_syntax;
207 
208  /* process digits */
209  while (*ptr && isdigit((unsigned char) *ptr))
210  {
211  int8 digit = (*ptr++ - '0');
212 
213  if (unlikely(pg_mul_s16_overflow(tmp, 10, &tmp)) ||
214  unlikely(pg_sub_s16_overflow(tmp, digit, &tmp)))
215  goto out_of_range;
216  }
217 
218  /* allow trailing whitespace, but not other trailing chars */
219  while (*ptr != '\0' && isspace((unsigned char) *ptr))
220  ptr++;
221 
222  if (unlikely(*ptr != '\0'))
223  goto invalid_syntax;
224 
225  if (!neg)
226  {
227  /* could fail if input is most negative number */
228  if (unlikely(tmp == PG_INT16_MIN))
229  goto out_of_range;
230  tmp = -tmp;
231  }
232 
233  return tmp;
234 
235 out_of_range:
236  ereport(ERROR,
237  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
238  errmsg("value \"%s\" is out of range for type %s",
239  s, "smallint")));
240 
241 invalid_syntax:
242  ereport(ERROR,
243  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
244  errmsg("invalid input syntax for type %s: \"%s\"",
245  "smallint", s)));
246 
247  return 0; /* keep compiler quiet */
248 }
signed short int16
Definition: c.h:354
#define likely(x)
Definition: c.h:205
int errcode(int sqlerrcode)
Definition: elog.c:610
static bool pg_mul_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:83
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:446
signed char int8
Definition: c.h:353
#define ereport(elevel,...)
Definition: elog.h:144
static bool pg_sub_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:65
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ pg_strtoint32()

int32 pg_strtoint32 ( const char *  s)

Definition at line 261 of file numutils.c.

References ereport, errcode(), errmsg(), ERROR, likely, PG_INT32_MIN, pg_mul_s32_overflow(), pg_sub_s32_overflow(), and unlikely.

Referenced by ArrayGetIntegerTypmods(), check_foreign_key(), int4in(), libpqrcv_endstreaming(), libpqrcv_identify_system(), pq_parse_errornotice(), prsd_headline(), and text_format().

262 {
263  const char *ptr = s;
264  int32 tmp = 0;
265  bool neg = false;
266 
267  /* skip leading spaces */
268  while (likely(*ptr) && isspace((unsigned char) *ptr))
269  ptr++;
270 
271  /* handle sign */
272  if (*ptr == '-')
273  {
274  ptr++;
275  neg = true;
276  }
277  else if (*ptr == '+')
278  ptr++;
279 
280  /* require at least one digit */
281  if (unlikely(!isdigit((unsigned char) *ptr)))
282  goto invalid_syntax;
283 
284  /* process digits */
285  while (*ptr && isdigit((unsigned char) *ptr))
286  {
287  int8 digit = (*ptr++ - '0');
288 
289  if (unlikely(pg_mul_s32_overflow(tmp, 10, &tmp)) ||
290  unlikely(pg_sub_s32_overflow(tmp, digit, &tmp)))
291  goto out_of_range;
292  }
293 
294  /* allow trailing whitespace, but not other trailing chars */
295  while (*ptr != '\0' && isspace((unsigned char) *ptr))
296  ptr++;
297 
298  if (unlikely(*ptr != '\0'))
299  goto invalid_syntax;
300 
301  if (!neg)
302  {
303  /* could fail if input is most negative number */
304  if (unlikely(tmp == PG_INT32_MIN))
305  goto out_of_range;
306  tmp = -tmp;
307  }
308 
309  return tmp;
310 
311 out_of_range:
312  ereport(ERROR,
313  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
314  errmsg("value \"%s\" is out of range for type %s",
315  s, "integer")));
316 
317 invalid_syntax:
318  ereport(ERROR,
319  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
320  errmsg("invalid input syntax for type %s: \"%s\"",
321  "integer", s)));
322 
323  return 0; /* keep compiler quiet */
324 }
#define likely(x)
Definition: c.h:205
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:140
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#define ERROR
Definition: elog.h:43
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:122
#define PG_INT32_MIN
Definition: c.h:449
signed char int8
Definition: c.h:353
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define unlikely(x)
Definition: c.h:206

◆ pg_strtouint64()

uint64 pg_strtouint64 ( const char *  str,
char **  endptr,
int  base 
)

Definition at line 615 of file numutils.c.

616 {
617 #ifdef _MSC_VER /* MSVC only */
618  return _strtoui64(str, endptr, base);
619 #elif defined(HAVE_STRTOULL) && SIZEOF_LONG < 8
620  return strtoull(str, endptr, base);
621 #else
622  return strtoul(str, endptr, base);
623 #endif
624 }

◆ pg_ulltoa_n()

int pg_ulltoa_n ( uint64  l,
char *  a 
)

Definition at line 432 of file numutils.c.

References decimalLength64(), DIGIT_TABLE, and i.

Referenced by pg_lltoa().

433 {
434  int olength,
435  i = 0;
436  uint32 value2;
437 
438 
439  /* Degenerate case */
440  if (value == 0)
441  {
442  *a = '0';
443  return 1;
444  }
445 
446  olength = decimalLength64(value);
447 
448  /* Compute the result string. */
449  while (value >= 100000000)
450  {
451  const uint64 q = value / 100000000;
452  uint32 value2 = (uint32) (value - 100000000 * q);
453 
454  const uint32 c = value2 % 10000;
455  const uint32 d = value2 / 10000;
456  const uint32 c0 = (c % 100) << 1;
457  const uint32 c1 = (c / 100) << 1;
458  const uint32 d0 = (d % 100) << 1;
459  const uint32 d1 = (d / 100) << 1;
460 
461  char *pos = a + olength - i;
462 
463  value = q;
464 
465  memcpy(pos - 2, DIGIT_TABLE + c0, 2);
466  memcpy(pos - 4, DIGIT_TABLE + c1, 2);
467  memcpy(pos - 6, DIGIT_TABLE + d0, 2);
468  memcpy(pos - 8, DIGIT_TABLE + d1, 2);
469  i += 8;
470  }
471 
472  /* Switch to 32-bit for speed */
473  value2 = (uint32) value;
474 
475  if (value2 >= 10000)
476  {
477  const uint32 c = value2 - 10000 * (value2 / 10000);
478  const uint32 c0 = (c % 100) << 1;
479  const uint32 c1 = (c / 100) << 1;
480 
481  char *pos = a + olength - i;
482 
483  value2 /= 10000;
484 
485  memcpy(pos - 2, DIGIT_TABLE + c0, 2);
486  memcpy(pos - 4, DIGIT_TABLE + c1, 2);
487  i += 4;
488  }
489  if (value2 >= 100)
490  {
491  const uint32 c = (value2 % 100) << 1;
492  char *pos = a + olength - i;
493 
494  value2 /= 100;
495 
496  memcpy(pos - 2, DIGIT_TABLE + c, 2);
497  i += 2;
498  }
499  if (value2 >= 10)
500  {
501  const uint32 c = value2 << 1;
502  char *pos = a + olength - i;
503 
504  memcpy(pos - 2, DIGIT_TABLE + c, 2);
505  }
506  else
507  *a = (char) ('0' + value2);
508 
509  return olength;
510 }
static int decimalLength64(const uint64 v)
Definition: numutils.c:62
char * c
unsigned int uint32
Definition: c.h:367
static struct @143 value
int i
static const char DIGIT_TABLE[200]
Definition: numutils.c:29

◆ pg_ultoa_n()

int pg_ultoa_n ( uint32  l,
char *  a 
)

Definition at line 348 of file numutils.c.

References decimalLength32(), DIGIT_TABLE, and i.

Referenced by pg_ltoa(), pg_ultostr(), and pg_ultostr_zeropad().

349 {
350  int olength,
351  i = 0;
352 
353  /* Degenerate case */
354  if (value == 0)
355  {
356  *a = '0';
357  return 1;
358  }
359 
360  olength = decimalLength32(value);
361 
362  /* Compute the result string. */
363  while (value >= 10000)
364  {
365  const uint32 c = value - 10000 * (value / 10000);
366  const uint32 c0 = (c % 100) << 1;
367  const uint32 c1 = (c / 100) << 1;
368 
369  char *pos = a + olength - i;
370 
371  value /= 10000;
372 
373  memcpy(pos - 2, DIGIT_TABLE + c0, 2);
374  memcpy(pos - 4, DIGIT_TABLE + c1, 2);
375  i += 4;
376  }
377  if (value >= 100)
378  {
379  const uint32 c = (value % 100) << 1;
380 
381  char *pos = a + olength - i;
382 
383  value /= 100;
384 
385  memcpy(pos - 2, DIGIT_TABLE + c, 2);
386  i += 2;
387  }
388  if (value >= 10)
389  {
390  const uint32 c = value << 1;
391 
392  char *pos = a + olength - i;
393 
394  memcpy(pos - 2, DIGIT_TABLE + c, 2);
395  }
396  else
397  {
398  *a = (char) ('0' + value);
399  }
400 
401  return olength;
402 }
static int decimalLength32(const uint32 v)
Definition: numutils.c:45
char * c
unsigned int uint32
Definition: c.h:367
static struct @143 value
int i
static const char DIGIT_TABLE[200]
Definition: numutils.c:29

◆ pg_ultostr()

char* pg_ultostr ( char *  str,
uint32  value 
)

Definition at line 597 of file numutils.c.

References pg_ultoa_n().

Referenced by AppendSeconds().

598 {
599  int len = pg_ultoa_n(value, str);
600 
601  return str + len;
602 }
static struct @143 value
int pg_ultoa_n(uint32 value, char *a)
Definition: numutils.c:348

◆ pg_ultostr_zeropad()

char* pg_ultostr_zeropad ( char *  str,
uint32  value,
int32  minwidth 
)

Definition at line 557 of file numutils.c.

References Assert, DIGIT_TABLE, and pg_ultoa_n().

Referenced by AppendSeconds(), EncodeDateOnly(), EncodeDateTime(), EncodeTimeOnly(), and EncodeTimezone().

558 {
559  int len;
560 
561  Assert(minwidth > 0);
562 
563  if (value < 100 && minwidth == 2) /* Short cut for common case */
564  {
565  memcpy(str, DIGIT_TABLE + value * 2, 2);
566  return str + 2;
567  }
568 
569  len = pg_ultoa_n(value, str);
570  if (len >= minwidth)
571  return str + len;
572 
573  memmove(str + minwidth - len, str, len);
574  memset(str, '0', minwidth - len);
575  return str + minwidth;
576 }
static struct @143 value
int pg_ultoa_n(uint32 value, char *a)
Definition: numutils.c:348
#define Assert(condition)
Definition: c.h:738
static const char DIGIT_TABLE[200]
Definition: numutils.c:29

◆ quote_identifier()

const char* quote_identifier ( const char *  ident)

Definition at line 10724 of file ruleutils.c.

References palloc(), pg_malloc(), quote_all_identifiers, ScanKeywordCategories, ScanKeywordLookup(), ScanKeywords, and UNRESERVED_KEYWORD.

Referenced by add_cast_to(), appendFunctionName(), ATPrepAlterColumnType(), copy_table(), decompile_column_index_array(), deparseAnalyzeSql(), deparseColumnRef(), deparseOperatorName(), deparseRelation(), DropSubscription(), execute_extension_script(), explain_get_index_name(), ExplainTargetRel(), flatten_set_variable_args(), format_operator_internal(), generate_operator_clause(), generate_operator_name(), get_column_alias_list(), get_delete_query_def(), get_from_clause_coldeflist(), get_from_clause_item(), get_insert_query_def(), get_opclass_name(), get_reloptions(), get_rule_expr(), get_rule_windowclause(), get_rule_windowspec(), get_select_query_def(), get_tablefunc(), get_target_list(), get_update_query_def(), get_update_query_targetlist_def(), get_utility_query_def(), get_variable(), get_windowfunc_expr(), get_with_clause(), getObjectIdentityParts(), initialize_worker_spi(), make_ruledef(), NameListToQuotedString(), old_9_6_invalidate_hash_indexes(), pg_get_constraintdef_worker(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), pg_get_statisticsobj_worker(), pg_get_triggerdef_worker(), pg_identify_object(), PLy_quote_ident(), postgresExplainForeignScan(), postgresImportForeignSchema(), print_function_arguments(), processIndirection(), quote_ident(), quote_object_name(), quote_qualified_identifier(), regnamespaceout(), regoperout(), regroleout(), sepgsql_attribute_post_create(), sepgsql_database_post_create(), sepgsql_relation_post_create(), sepgsql_schema_post_create(), serialize_deflist(), set_frozenxids(), show_sortorder_options(), text_format_string_conversion(), and tuple_to_stringinfo().

10725 {
10726  /*
10727  * Can avoid quoting if ident starts with a lowercase letter or underscore
10728  * and contains only lowercase letters, digits, and underscores, *and* is
10729  * not any SQL keyword. Otherwise, supply quotes.
10730  */
10731  int nquotes = 0;
10732  bool safe;
10733  const char *ptr;
10734  char *result;
10735  char *optr;
10736 
10737  /*
10738  * would like to use <ctype.h> macros here, but they might yield unwanted
10739  * locale-specific results...
10740  */
10741  safe = ((ident[0] >= 'a' && ident[0] <= 'z') || ident[0] == '_');
10742 
10743  for (ptr = ident; *ptr; ptr++)
10744  {
10745  char ch = *ptr;
10746 
10747  if ((ch >= 'a' && ch <= 'z') ||
10748  (ch >= '0' && ch <= '9') ||
10749  (ch == '_'))
10750  {
10751  /* okay */
10752  }
10753  else
10754  {
10755  safe = false;
10756  if (ch == '"')
10757  nquotes++;
10758  }
10759  }
10760 
10762  safe = false;
10763 
10764  if (safe)
10765  {
10766  /*
10767  * Check for keyword. We quote keywords except for unreserved ones.
10768  * (In some cases we could avoid quoting a col_name or type_func_name
10769  * keyword, but it seems much harder than it's worth to tell that.)
10770  *
10771  * Note: ScanKeywordLookup() does case-insensitive comparison, but
10772  * that's fine, since we already know we have all-lower-case.
10773  */
10774  int kwnum = ScanKeywordLookup(ident, &ScanKeywords);
10775 
10776  if (kwnum >= 0 && ScanKeywordCategories[kwnum] != UNRESERVED_KEYWORD)
10777  safe = false;
10778  }
10779 
10780  if (safe)
10781  return ident; /* no change needed */
10782 
10783  result = (char *) palloc(strlen(ident) + nquotes + 2 + 1);
10784 
10785  optr = result;
10786  *optr++ = '"';
10787  for (ptr = ident; *ptr; ptr++)
10788  {
10789  char ch = *ptr;
10790 
10791  if (ch == '"')
10792  *optr++ = '"';
10793  *optr++ = ch;
10794  }
10795  *optr++ = '"';
10796  *optr = '\0';
10797 
10798  return result;
10799 }
const uint8 ScanKeywordCategories[SCANKEYWORDS_NUM_KEYWORDS]
Definition: keywords.c:29
#define UNRESERVED_KEYWORD
Definition: keywords.h:20
PGDLLIMPORT const ScanKeywordList ScanKeywords
bool quote_all_identifiers
Definition: ruleutils.c:316
void * palloc(Size size)
Definition: mcxt.c:949
int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords)
Definition: kwlookup.c:38

◆ quote_literal_cstr()

char* quote_literal_cstr ( const char *  rawstr)

Definition at line 102 of file quote.c.

References palloc(), and quote_literal_internal().

Referenced by build_tuplestore_recursively(), fetch_remote_table_info(), fetch_table_list(), get_sql_delete(), get_sql_insert(), get_sql_update(), get_tuple_of_interest(), PLy_quote_literal(), PLy_quote_nullable(), and text_format_string_conversion().

103 {
104  char *result;
105  int len;
106  int newlen;
107 
108  len = strlen(rawstr);
109  /* We make a worst-case result area; wasting a little space is OK */
110  result = palloc(len * 2 + 3 + 1);
111 
112  newlen = quote_literal_internal(result, rawstr, len);
113  result[newlen] = '\0';
114 
115  return result;
116 }
static size_t quote_literal_internal(char *dst, const char *src, size_t len)
Definition: quote.c:46
void * palloc(Size size)
Definition: mcxt.c:949

◆ quote_qualified_identifier()

char* quote_qualified_identifier ( const char *  qualifier,
const char *  ident 
)

Definition at line 10808 of file ruleutils.c.

References appendStringInfo(), appendStringInfoString(), buf, StringInfoData::data, initStringInfo(), and quote_identifier().

Referenced by check_TSCurrentConfig(), copy_table(), ExecRefreshMatView(), format_procedure_internal(), format_type_extended(), generate_collation_name(), generate_function_name(), generate_qualified_relation_name(), generate_qualified_type_name(), generate_relation_name(), getObjectDescription(), getObjectIdentityParts(), getOpFamilyDescription(), getOpFamilyIdentity(), getRelationDescription(), getRelationIdentity(), pg_decode_change(), pg_decode_truncate(), pg_get_functiondef(), pg_get_statisticsobj_worker(), pg_newlocale_from_collation(), refresh_by_match_merge(), regclassout(), regcollationout(), regconfigout(), regdictionaryout(), regprocout(), sepgsql_proc_post_create(), and transformColumnDefinition().

10810 {
10812 
10813  initStringInfo(&buf);
10814  if (qualifier)
10815  appendStringInfo(&buf, "%s.", quote_identifier(qualifier));
10817  return buf.data;
10818 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10724
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
static char * buf
Definition: pg_test_fsync.c:67
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

◆ regexp_fixed_prefix()

char* regexp_fixed_prefix ( text text_re,
bool  case_insensitive,
Oid  collation,
bool exact 
)

Definition at line 1499 of file regexp.c.

References Assert, pg_re_flags::cflags, CHECK_FOR_INTERRUPTS, ereport, errcode(), errmsg(), ERROR, free, palloc(), pg_database_encoding_max_length(), pg_regerror(), pg_regprefix(), pg_wchar2mb_with_len(), RE_compile_and_cache(), REG_ADVANCED, REG_EXACT, REG_ICASE, REG_NOMATCH, REG_PREFIX, and generate_unaccent_rules::str.

Referenced by regex_fixed_prefix().

1501 {
1502  char *result;
1503  regex_t *re;
1504  int cflags;
1505  int re_result;
1506  pg_wchar *str;
1507  size_t slen;
1508  size_t maxlen;
1509  char errMsg[100];
1510 
1511  *exact = false; /* default result */
1512 
1513  /* Compile RE */
1514  cflags = REG_ADVANCED;
1515  if (case_insensitive)
1516  cflags |= REG_ICASE;
1517 
1518  re = RE_compile_and_cache(text_re, cflags, collation);
1519 
1520  /* Examine it to see if there's a fixed prefix */
1521  re_result = pg_regprefix(re, &str, &slen);
1522 
1523  switch (re_result)
1524  {
1525  case REG_NOMATCH:
1526  return NULL;
1527 
1528  case REG_PREFIX:
1529  /* continue with wchar conversion */
1530  break;
1531 
1532  case REG_EXACT:
1533  *exact = true;
1534  /* continue with wchar conversion */
1535  break;
1536 
1537  default:
1538  /* re failed??? */
1540  pg_regerror(re_result, re, errMsg, sizeof(errMsg));
1541  ereport(ERROR,
1542  (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
1543  errmsg("regular expression failed: %s", errMsg)));
1544  break;
1545  }
1546 
1547  /* Convert pg_wchar result back to database encoding */
1548  maxlen = pg_database_encoding_max_length() * slen + 1;
1549  result = (char *) palloc(maxlen);
1550  slen = pg_wchar2mb_with_len(str, result, slen);
1551  Assert(slen < maxlen);
1552 
1553  free(str);
1554 
1555  return result;
1556 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define REG_PREFIX
Definition: regex.h:162
#define REG_ICASE
Definition: regex.h:106
int pg_regprefix(regex_t *re, chr **string, size_t *slength)
Definition: regprefix.c:46
#define ERROR
Definition: elog.h:43
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
Definition: regerror.c:60
#define REG_ADVANCED
Definition: regex.h:103
unsigned int pg_wchar
Definition: mbprint.c:31
#define ereport(elevel,...)
Definition: elog.h:144
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:738
regex_t * RE_compile_and_cache(text *text_re, int cflags, Oid collation)
Definition: regexp.c:137
int pg_database_encoding_max_length(void)
Definition: mbutils.c:1436
#define REG_EXACT
Definition: regex.h:163
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define REG_NOMATCH
Definition: regex.h:138
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
int pg_wchar2mb_with_len(const pg_wchar *from, char *to, int len)
Definition: mbutils.c:892
Definition: regex.h:55

◆ text_to_cstring()

char* text_to_cstring ( const text t)

Definition at line 205 of file varlena.c.

References palloc(), pfree(), pg_detoast_datum_packed(), unconstify, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by array_to_text(), array_to_text_null(), binary_upgrade_create_empty_extension(), binary_upgrade_set_missing_value(), connectby_text(), connectby_text_serial(), convert_and_check_filename(), convert_any_priv_string(), convert_column_name(), convert_database_name(), convert_foreign_data_wrapper_name(), convert_function_name(), convert_language_name(), convert_priv_string(), convert_schema_name(), convert_server_name(), convert_tablespace_name(), convert_type_name(), crosstab(), crosstab_hash(), cursor_to_xml(), cursor_to_xmlschema(), database_to_xml(), database_to_xml_and_xmlschema(), database_to_xmlschema(), datetime_to_char_body(), datum_to_json(), dblink_cancel_query(), dblink_close(), dblink_connect(), dblink_disconnect(), dblink_error_message(), dblink_exec(), dblink_fetch(), dblink_get_notify(), dblink_is_busy(), dblink_open(), dblink_record_internal(), dblink_send_query(), deserialize_deflist(), difference(), dmetaphone(), dmetaphone_alt(), do_to_timestamp(), ExecAlterExtensionStmt(), execute_extension_script(), executeDateTimeMethod(), get_raw_page_fork(), has_sequence_privilege_id_name(), has_sequence_privilege_name(), has_sequence_privilege_name_name(), json_object_field(), json_object_field_text(), jsonb_set_lax(), ltree_addtext(), ltree_textadd(), NUM_cache(), parse_datetime(), parse_ident(), pg_create_restore_point(), pg_crypt(), pg_current_logfile(), pg_get_expr_worker(), pg_get_publication_tables(), pg_get_serial_sequence(), pg_index_column_has_property(), pg_index_has_property(), pg_indexam_has_property(), pg_logical_emit_message_bytea(), pg_notify(), pg_prewarm(), pg_relation_size(), pg_replication_origin_advance(), pg_replication_origin_create(), pg_replication_origin_drop(), pg_replication_origin_oid(), pg_replication_origin_progress(), pg_replication_origin_session_setup(), pg_size_bytes(), pg_start_backup(), pg_stat_get_progress_info(), pg_stat_reset_shared(), pg_stat_reset_slru(), pgxml_texttoxmlchar(), phraseto_tsquery_byid(), plainto_tsquery_byid(), query_to_xml(), query_to_xml_and_xmlschema(), query_to_xmlschema(), quote_ident(), quote_ident_cstr(), range_constructor3(), regress_putenv(), replorigin_by_oid(), schema_to_xml(), schema_to_xml_and_xmlschema(), schema_to_xmlschema(), sepgsql_mcstrans_in(), sepgsql_mcstrans_out(), soundex(), table_to_xml(), table_to_xml_and_xmlschema(), table_to_xmlschema(), test_predtest(), text2ltree(), text_concat_ws(), textToQualifiedNameList(), to_date(), to_regclass(), to_regcollation(), to_regnamespace(), to_regoper(), to_regoperator(), to_regproc(), to_regprocedure(), to_regrole(), to_regtype(), to_timestamp(), to_tsquery_byid(), transform_string_values_scalar(), ts_stat_sql(), tsquery_rewrite_query(), tuple_data_split(), unicode_is_normalized(), unicode_normalize_func(), websearch_to_tsquery_byid(), X509_NAME_field_to_text(), xml_is_document(), xml_out_internal(), xmlconcat(), xmlpi(), xmlroot(), xpath_table(), and xslt_process().

206 {
207  /* must cast away the const, unfortunately */
208  text *tunpacked = pg_detoast_datum_packed(unconstify(text *, t));
209  int len = VARSIZE_ANY_EXHDR(tunpacked);
210  char *result;
211 
212  result = (char *) palloc(len + 1);
213  memcpy(result, VARDATA_ANY(tunpacked), len);
214  result[len] = '\0';
215 
216  if (tunpacked != t)
217  pfree(tunpacked);
218 
219  return result;
220 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
void pfree(void *pointer)
Definition: mcxt.c:1056
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
Definition: fmgr.c:1758
#define unconstify(underlying_type, expr)
Definition: c.h:1206
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
void * palloc(Size size)
Definition: mcxt.c:949
Definition: c.h:555

◆ text_to_cstring_buffer()

void text_to_cstring_buffer ( const text src,
char *  dst,
size_t  dst_len 
)

Definition at line 236 of file varlena.c.

References pfree(), pg_detoast_datum_packed(), pg_mbcliplen(), unconstify, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by be_lo_export(), lo_import_internal(), parse_sane_timezone(), pg_gen_salt(), pg_gen_salt_rounds(), timestamp_zone(), timestamptz_trunc_zone(), timestamptz_zone(), and timetz_zone().

237 {
238  /* must cast away the const, unfortunately */
239  text *srcunpacked = pg_detoast_datum_packed(unconstify(text *, src));
240  size_t src_len = VARSIZE_ANY_EXHDR(srcunpacked);
241 
242  if (dst_len > 0)
243  {
244  dst_len--;
245  if (dst_len >= src_len)
246  dst_len = src_len;
247  else /* ensure truncation is encoding-safe */
248  dst_len = pg_mbcliplen(VARDATA_ANY(srcunpacked), src_len, dst_len);
249  memcpy(dst, VARDATA_ANY(srcunpacked), dst_len);
250  dst[dst_len] = '\0';
251  }
252 
253  if (srcunpacked != src)
254  pfree(srcunpacked);
255 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
void pfree(void *pointer)
Definition: mcxt.c:1056
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
Definition: fmgr.c:1758
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:967
#define unconstify(underlying_type, expr)
Definition: c.h:1206
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
Definition: c.h:555

◆ type_maximum_size()

int32 type_maximum_size ( Oid  type_oid,
int32  typemod 
)

Definition at line 396 of file format_type.c.

References BITS_PER_BYTE, GetDatabaseEncoding(), numeric_maximum_size(), pg_encoding_max_length(), and VARHDRSZ.

Referenced by get_typavgwidth(), and heapam_relation_needs_toast_table().

397 {
398  if (typemod < 0)
399  return -1;
400 
401  switch (type_oid)
402  {
403  case BPCHAROID:
404  case VARCHAROID:
405  /* typemod includes varlena header */
406 
407  /* typemod is in characters not bytes */
408  return (typemod - VARHDRSZ) *
410  + VARHDRSZ;
411 
412  case NUMERICOID:
413  return numeric_maximum_size(typemod);
414 
415  case VARBITOID:
416  case BITOID:
417  /* typemod is the (max) number of bits */
418  return (typemod + (BITS_PER_BYTE - 1)) / BITS_PER_BYTE
419  + 2 * sizeof(int32);
420  }
421 
422  /* Unknown type, or unlimited-width type such as 'text' */
423  return -1;
424 }
#define BITS_PER_BYTE
#define VARHDRSZ
Definition: c.h:561
signed int int32
Definition: c.h:355
int pg_encoding_max_length(int encoding)
Definition: wchar.c:1589
int GetDatabaseEncoding(void)
Definition: mbutils.c:1151
int32 numeric_maximum_size(int32 typmod)
Definition: numeric.c:688

◆ xidComparator()

int xidComparator ( const void *  arg1,
const void *  arg2 
)

Definition at line 138 of file xid.c.

Referenced by ProcArrayApplyRecoveryInfo(), ReorderBufferCopySnap(), SerializeTransactionState(), SnapBuildBuildSnapshot(), SnapBuildInitialSnapshot(), and TransactionIdInArray().

139 {
140  TransactionId xid1 = *(const TransactionId *) arg1;
141  TransactionId xid2 = *(const TransactionId *) arg2;
142 
143  if (xid1 > xid2)
144  return 1;
145  if (xid1 < xid2)
146  return -1;
147  return 0;
148 }
uint32 TransactionId
Definition: c.h:513

Variable Documentation

◆ quote_all_identifiers

bool quote_all_identifiers

Definition at line 316 of file ruleutils.c.

Referenced by fmtId(), main(), quote_identifier(), and setup_connection().