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 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)
 
void pg_ltoa (int32 l, char *a)
 
void pg_lltoa (int64 ll, char *a)
 
char * pg_ltostr_zeropad (char *str, int32 value, int32 minwidth)
 
char * pg_ltostr (char *str, int32 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 * inet_cidr_ntop (int af, const void *src, int bits, char *dst, size_t size)
 
int 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 83 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(), 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(), 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_identify_object(), pg_identify_object_as_address(), 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 110 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 111 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 */

◆ TextDatumGetCString

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

Definition at line 84 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(), DecodeTextArrayToCString(), 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(), find_language_template(), flatten_reloptions(), 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(), 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_role_password(), get_text_array_contents(), get_typdefault(), GetAggInitVal(), GetComment(), GetForeignServer(), GetSecurityLabel(), GetSharedSecurityLabel(), GetSubscription(), GUCArrayAdd(), GUCArrayDelete(), GUCArrayReset(), 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(), parseRelOptions(), patternsel(), 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(), prefix_quals(), print_function_arguments(), ProcedureCreate(), ProcessGUCArray(), regex_fixed_prefix(), RelationBuildPartitionDesc(), RelationBuildPartitionKey(), RelationBuildRowSecurity(), RelationBuildRuleLock(), RelationBuildTriggers(), 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 660 of file varchar.c.

References i.

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

661 {
662  int i;
663 
664  /*
665  * Note that we rely on the assumption that ' ' is a singleton unit on
666  * every supported multibyte server encoding.
667  */
668  for (i = len - 1; i >= 0; i--)
669  {
670  if (s[i] != ' ')
671  break;
672  }
673  return i + 1;
674 }
int i

◆ buildint2vector()

int2vector* buildint2vector ( const int16 int2s,
int  n 
)

Definition at line 110 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().

111 {
112  int2vector *result;
113 
114  result = (int2vector *) palloc0(Int2VectorSize(n));
115 
116  if (n > 0 && int2s)
117  memcpy(result->values, int2s, n * sizeof(int16));
118 
119  /*
120  * Attach standard array header. For historical reasons, we set the index
121  * lower bound to 0 not 1.
122  */
123  SET_VARSIZE(result, Int2VectorSize(n));
124  result->ndim = 1;
125  result->dataoffset = 0; /* never any nulls */
126  result->elemtype = INT2OID;
127  result->dim1 = n;
128  result->lbound1 = 0;
129 
130  return result;
131 }
signed short int16
Definition: c.h:345
int lbound1
Definition: c.h:584
Oid elemtype
Definition: c.h:582
int32 dataoffset
Definition: c.h:581
int ndim
Definition: c.h:580
Definition: c.h:577
void * palloc0(Size size)
Definition: mcxt.c:955
int dim1
Definition: c.h:583
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:585
#define Int2VectorSize(n)
Definition: int.c:41
#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 CreateProceduralLanguage(), 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:588
int32 dataoffset
Definition: c.h:592
unsigned int Oid
Definition: postgres_ext.h:31
#define OidVectorSize(n)
Definition: oid.c:27
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:596
int dim1
Definition: c.h:594
void * palloc0(Size size)
Definition: mcxt.c:955
int lbound1
Definition: c.h:595
Oid elemtype
Definition: c.h:593
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
int ndim
Definition: c.h:591

◆ clean_ipv6_addr()

void clean_ipv6_addr ( int  addr_family,
char *  addr 
)

Definition at line 1511 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().

1512 {
1513 #ifdef HAVE_IPV6
1514  if (addr_family == AF_INET6)
1515  {
1516  char *pct = strchr(addr, '%');
1517 
1518  if (pct)
1519  *pct = '\0';
1520  }
1521 #endif
1522 }

◆ convert_network_to_scalar()

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

Definition at line 910 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().

911 {
912  switch (typid)
913  {
914  case INETOID:
915  case CIDROID:
916  {
917  inet *ip = DatumGetInetPP(value);
918  int len;
919  double res;
920  int i;
921 
922  /*
923  * Note that we don't use the full address for IPv6.
924  */
925  if (ip_family(ip) == PGSQL_AF_INET)
926  len = 4;
927  else
928  len = 5;
929 
930  res = ip_family(ip);
931  for (i = 0; i < len; i++)
932  {
933  res *= 256;
934  res += ip_addr(ip)[i];
935  }
936  return res;
937  }
938  case MACADDROID:
939  {
941  double res;
942 
943  res = (mac->a << 16) | (mac->b << 8) | (mac->c);
944  res *= 256 * 256 * 256;
945  res += (mac->d << 16) | (mac->e << 8) | (mac->f);
946  return res;
947  }
948  case MACADDR8OID:
949  {
951  double res;
952 
953  res = (mac->a << 24) | (mac->b << 16) | (mac->c << 8) | (mac->d);
954  res *= ((double) 256) * 256 * 256 * 256;
955  res += (mac->e << 24) | (mac->f << 16) | (mac->g << 8) | (mac->h);
956  return res;
957  }
958  }
959 
960  *failure = true;
961  return 0;
962 }
#define DatumGetMacaddrP(X)
Definition: inet.h:131
static struct @130 value
#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
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 149 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(), 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_array_element_text(), jsonb_object_field_text(), jsonb_typeof(), 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_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().

150 {
151  return cstring_to_text_with_len(s, strlen(s));
152 }
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:161

◆ cstring_to_text_with_len()

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

Definition at line 161 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(), elements_worker_jsonb(), ExecEvalXmlExpr(), fsm_page_contents(), get_array_element_end(), get_array_end(), get_jsonb_path_all(), 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_array_element_text(), jsonb_object_field_text(), jsonb_pretty(), 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(), 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().

162 {
163  text *result = (text *) palloc(len + VARHDRSZ);
164 
165  SET_VARSIZE(result, len + VARHDRSZ);
166  memcpy(VARDATA(result), s, len);
167 
168  return result;
169 }
#define VARDATA(PTR)
Definition: postgres.h:302
#define VARHDRSZ
Definition: c.h:555
void * palloc(Size size)
Definition: mcxt.c:924
Definition: c.h:549
#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 }
static struct @130 value
Oid domain_type
Definition: domains.c:49
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
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:492
#define ERROR
Definition: elog.h:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3042
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#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:250
#define elog(elevel,...)
Definition: elog.h:226
#define NameStr(name)
Definition: c.h:609
int err_generic_string(int field, const char *str)
Definition: elog.c:1178

◆ 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:1178

◆ format_type_be()

char* format_type_be ( Oid  type_oid)

Definition at line 328 of file format_type.c.

References format_type_extended().

Referenced by aclcheck_error_type(), addFamilyMember(), addRangeTableEntryForFunction(), AggregateCreate(), 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_column_default(), build_pertrans_for_aggref(), build_subplan(), check_object_ownership(), check_of_type(), check_safe_enum_use(), check_sql_fn_retval(), 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(), convert_tuples_by_name_map(), 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(), findTypeOutputFunction(), 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(), init_sql_fcache(), initArrayResultArr(), initGinState(), internal_get_result_type(), intorel_startup(), load_enum_cache_data(), logicalrep_typmap_gettypname(), lookup_rowtype_tupdesc_domain(), lookup_rowtype_tupdesc_internal(), LookupTypeName(), 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_generic_type(), ResolveOpClass(), ri_HashCompareOp(), satisfies_hash_partition(), select_common_type(), slot_store_error_callback(), spgvalidate(), storeOperators(), storeProcedures(), transformAggregateCall(), transformArrayExpr(), transformArraySubscripts(), transformArrayType(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformCollateClause(), transformColumnType(), transformFrameOffset(), transformPartitionBoundValue(), transformTypeCast(), transformXmlSerialize(), tuple_equals_slot(), tuple_to_stringinfo(), tupledesc_match(), unknown_attribute(), validateConnectbyTupleDesc(), variable_coerce_param_hook(), and width_bucket_array().

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

◆ format_type_be_qualified()

char* format_type_be_qualified ( Oid  type_oid)

Definition at line 338 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().

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

◆ format_type_extended()

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

Definition at line 110 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(), and oidvectortypes().

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

◆ 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 10968 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().

10972 {
10973  HeapTuple opertup;
10974  Form_pg_operator operform;
10975  char *oprname;
10976  char *nspname;
10977 
10978  opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(opoid));
10979  if (!HeapTupleIsValid(opertup))
10980  elog(ERROR, "cache lookup failed for operator %u", opoid);
10981  operform = (Form_pg_operator) GETSTRUCT(opertup);
10982  Assert(operform->oprkind == 'b');
10983  oprname = NameStr(operform->oprname);
10984 
10985  nspname = get_namespace_name(operform->oprnamespace);
10986 
10987  appendStringInfoString(buf, leftop);
10988  if (leftoptype != operform->oprleft)
10989  add_cast_to(buf, operform->oprleft);
10990  appendStringInfo(buf, " OPERATOR(%s.", quote_identifier(nspname));
10991  appendStringInfoString(buf, oprname);
10992  appendStringInfo(buf, ") %s", rightop);
10993  if (rightoptype != operform->oprright)
10994  add_cast_to(buf, operform->oprright);
10995 
10996  ReleaseSysCache(opertup);
10997 }
static void add_cast_to(StringInfo buf, Oid typid)
Definition: ruleutils.c:11008
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10554
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:163
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3042
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:732
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:84
#define elog(elevel,...)
Definition: elog.h:226
#define NameStr(name)
Definition: c.h:609

◆ 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:570
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
static char get_hex(char c)
Definition: encode.c:140
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ hex_encode()

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

Definition at line 126 of file encode.c.

References hextbl.

Referenced by byteaout().

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

◆ inet_cidr_ntop()

char* 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:336

◆ inet_net_pton()

int 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:336
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)

◆ namecpy()

int namecpy ( Name  n1,
const NameData n2 
)

Definition at line 191 of file name.c.

References NAMEDATALEN, NameStr, and StrNCpy.

Referenced by ConstructTupleDescriptor(), and pg_get_replication_slots().

192 {
193  if (!n1 || !n2)
194  return -1;
195  StrNCpy(NameStr(*n1), NameStr(*n2), NAMEDATALEN);
196  return 0;
197 }
#define NAMEDATALEN
#define StrNCpy(dst, src, len)
Definition: c.h:914
#define NameStr(name)
Definition: c.h:609

◆ namestrcmp()

int namestrcmp ( Name  name,
const char *  str 
)

Definition at line 247 of file name.c.

References NAMEDATALEN, and NameStr.

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

248 {
249  if (!name && !str)
250  return 0;
251  if (!name)
252  return -1; /* NULL < anything */
253  if (!str)
254  return 1; /* NULL < anything */
255  return strncmp(NameStr(*name), str, NAMEDATALEN);
256 }
#define NAMEDATALEN
#define NameStr(name)
Definition: c.h:609

◆ namestrcpy()

◆ network_scan_first()

Datum network_scan_first ( Datum  in)

Definition at line 1098 of file network.c.

References DirectFunctionCall1, and network_network().

Referenced by network_prefix_quals().

1099 {
1101 }
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:590
Datum network_network(PG_FUNCTION_ARGS)
Definition: network.c:738

◆ network_scan_last()

Datum network_scan_last ( Datum  in)

Definition at line 1112 of file network.c.

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

Referenced by network_prefix_quals().

1113 {
1116  Int32GetDatum(-1));
1117 }
Datum network_broadcast(PG_FUNCTION_ARGS)
Definition: network.c:693
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:590
Datum inet_set_masklen(PG_FUNCTION_ARGS)
Definition: network.c:283
#define Int32GetDatum(X)
Definition: postgres.h:464
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592

◆ numeric_float8_no_overflow()

Datum numeric_float8_no_overflow ( PG_FUNCTION_ARGS  )

Definition at line 3288 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().

3289 {
3290  Numeric num = PG_GETARG_NUMERIC(0);
3291  double val;
3292 
3293  if (NUMERIC_IS_NAN(num))
3295 
3296  val = numeric_to_double_no_overflow(num);
3297 
3298  PG_RETURN_FLOAT8(val);
3299 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
static float8 get_float8_nan(void)
Definition: float.h:116
#define PG_GETARG_NUMERIC(n)
Definition: numeric.h:52
static double numeric_to_double_no_overflow(Numeric num)
Definition: numeric.c:6501
#define NUMERIC_IS_NAN(n)
Definition: numeric.c:172
long val
Definition: informix.c:689

◆ 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:522
Definition: nodes.h:288
#define intVal(v)
Definition: value.h:52
#define elog(elevel,...)
Definition: elog.h:226

◆ 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_extension_control_file(), parse_one_reloption(), pg_decode_startup(), and ProcessStartupPacket().

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

◆ 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 }
static struct @130 value
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69

◆ pg_atoi()

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

Definition at line 38 of file numutils.c.

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

Referenced by int2vectorin().

39 {
40  long l;
41  char *badp;
42 
43  /*
44  * Some versions of strtol treat the empty string as an error, but some
45  * seem not to. Make an explicit test to be sure we catch it.
46  */
47  if (s == NULL)
48  elog(ERROR, "NULL pointer");
49  if (*s == 0)
50  ereport(ERROR,
51  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
52  errmsg("invalid input syntax for type %s: \"%s\"",
53  "integer", s)));
54 
55  errno = 0;
56  l = strtol(s, &badp, 10);
57 
58  /* We made no progress parsing the string, so bail out */
59  if (s == badp)
60  ereport(ERROR,
61  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
62  errmsg("invalid input syntax for type %s: \"%s\"",
63  "integer", s)));
64 
65  switch (size)
66  {
67  case sizeof(int32):
68  if (errno == ERANGE
69 #if defined(HAVE_LONG_INT_64)
70  /* won't get ERANGE on these with 64-bit longs... */
71  || l < INT_MIN || l > INT_MAX
72 #endif
73  )
74  ereport(ERROR,
75  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
76  errmsg("value \"%s\" is out of range for type %s", s,
77  "integer")));
78  break;
79  case sizeof(int16):
80  if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX)
81  ereport(ERROR,
82  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
83  errmsg("value \"%s\" is out of range for type %s", s,
84  "smallint")));
85  break;
86  case sizeof(int8):
87  if (errno == ERANGE || l < SCHAR_MIN || l > SCHAR_MAX)
88  ereport(ERROR,
89  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
90  errmsg("value \"%s\" is out of range for 8-bit integer", s)));
91  break;
92  default:
93  elog(ERROR, "unsupported result size: %d", size);
94  }
95 
96  /*
97  * Skip any trailing whitespace; if anything but whitespace remains before
98  * the terminating character, bail out
99  */
100  while (*badp && *badp != c && isspace((unsigned char) *badp))
101  badp++;
102 
103  if (*badp && *badp != c)
104  ereport(ERROR,
105  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
106  errmsg("invalid input syntax for type %s: \"%s\"",
107  "integer", s)));
108 
109  return (int32) l;
110 }
signed short int16
Definition: c.h:345
int errcode(int sqlerrcode)
Definition: elog.c:570
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
char * c
#define ereport(elevel, rest)
Definition: elog.h:141
signed char int8
Definition: c.h:344
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226

◆ pg_itoa()

void pg_itoa ( int16  i,
char *  a 
)

Definition at line 273 of file numutils.c.

References pg_ltoa().

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

274 {
275  pg_ltoa((int32) i, a);
276 }
signed int int32
Definition: c.h:346
int i
void pg_ltoa(int32 value, char *a)
Definition: numutils.c:285

◆ pg_lltoa()

void pg_lltoa ( int64  ll,
char *  a 
)

Definition at line 339 of file numutils.c.

References PG_INT64_MIN, swap, and value.

Referenced by int8out(), and printsimple().

340 {
341  char *start = a;
342  bool neg = false;
343 
344  /*
345  * Avoid problems with the most negative integer not being representable
346  * as a positive integer.
347  */
348  if (value == PG_INT64_MIN)
349  {
350  memcpy(a, "-9223372036854775808", 21);
351  return;
352  }
353  else if (value < 0)
354  {
355  value = -value;
356  neg = true;
357  }
358 
359  /* Compute the result string backwards. */
360  do
361  {
362  int64 remainder;
363  int64 oldval = value;
364 
365  value /= 10;
366  remainder = oldval - value * 10;
367  *a++ = '0' + remainder;
368  } while (value != 0);
369 
370  if (neg)
371  *a++ = '-';
372 
373  /* Add trailing NUL byte, and back up 'a' to the last character. */
374  *a-- = '\0';
375 
376  /* Reverse string. */
377  while (start < a)
378  {
379  char swap = *start;
380 
381  *start++ = *a;
382  *a-- = swap;
383  }
384 }
#define swap(a, b)
Definition: qsort.c:94
static struct @130 value
#define PG_INT64_MIN
Definition: c.h:443

◆ pg_ltoa()

void pg_ltoa ( int32  l,
char *  a 
)

Definition at line 285 of file numutils.c.

References PG_INT32_MIN, swap, and value.

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

286 {
287  char *start = a;
288  bool neg = false;
289 
290  /*
291  * Avoid problems with the most negative integer not being representable
292  * as a positive integer.
293  */
294  if (value == PG_INT32_MIN)
295  {
296  memcpy(a, "-2147483648", 12);
297  return;
298  }
299  else if (value < 0)
300  {
301  value = -value;
302  neg = true;
303  }
304 
305  /* Compute the result string backwards. */
306  do
307  {
308  int32 remainder;
309  int32 oldval = value;
310 
311  value /= 10;
312  remainder = oldval - value * 10;
313  *a++ = '0' + remainder;
314  } while (value != 0);
315 
316  if (neg)
317  *a++ = '-';
318 
319  /* Add trailing NUL byte, and back up 'a' to the last character. */
320  *a-- = '\0';
321 
322  /* Reverse string. */
323  while (start < a)
324  {
325  char swap = *start;
326 
327  *start++ = *a;
328  *a-- = swap;
329  }
330 }
#define swap(a, b)
Definition: qsort.c:94
static struct @130 value
signed int int32
Definition: c.h:346
#define PG_INT32_MIN
Definition: c.h:440

◆ pg_ltostr()

char* pg_ltostr ( char *  str,
int32  value 
)

Definition at line 487 of file numutils.c.

References generate_unaccent_rules::str, swap, and value.

Referenced by AppendSeconds(), and pg_ltostr_zeropad().

488 {
489  char *start;
490  char *end;
491 
492  /*
493  * Handle negative numbers in a special way. We can't just write a '-'
494  * prefix and reverse the sign as that would overflow for INT32_MIN.
495  */
496  if (value < 0)
497  {
498  *str++ = '-';
499 
500  /* Mark the position we must reverse the string from. */
501  start = str;
502 
503  /* Compute the result string backwards. */
504  do
505  {
506  int32 oldval = value;
507  int32 remainder;
508 
509  value /= 10;
510  remainder = oldval - value * 10;
511  /* As above, we expect remainder to be negative. */
512  *str++ = '0' - remainder;
513  } while (value != 0);
514  }
515  else
516  {
517  /* Mark the position we must reverse the string from. */
518  start = str;
519 
520  /* Compute the result string backwards. */
521  do
522  {
523  int32 oldval = value;
524  int32 remainder;
525 
526  value /= 10;
527  remainder = oldval - value * 10;
528  *str++ = '0' + remainder;
529  } while (value != 0);
530  }
531 
532  /* Remember the end+1 and back up 'str' to the last character. */
533  end = str--;
534 
535  /* Reverse string. */
536  while (start < str)
537  {
538  char swap = *start;
539 
540  *start++ = *str;
541  *str-- = swap;
542  }
543 
544  return end;
545 }
#define swap(a, b)
Definition: qsort.c:94
static struct @130 value
signed int int32
Definition: c.h:346

◆ pg_ltostr_zeropad()

char* pg_ltostr_zeropad ( char *  str,
int32  value,
int32  minwidth 
)

Definition at line 410 of file numutils.c.

References Assert, pg_ltostr(), generate_unaccent_rules::str, and value.

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

411 {
412  char *start = str;
413  char *end = &str[minwidth];
414  int32 num = value;
415 
416  Assert(minwidth > 0);
417 
418  /*
419  * Handle negative numbers in a special way. We can't just write a '-'
420  * prefix and reverse the sign as that would overflow for INT32_MIN.
421  */
422  if (num < 0)
423  {
424  *start++ = '-';
425  minwidth--;
426 
427  /*
428  * Build the number starting at the last digit. Here remainder will
429  * be a negative number, so we must reverse the sign before adding '0'
430  * in order to get the correct ASCII digit.
431  */
432  while (minwidth--)
433  {
434  int32 oldval = num;
435  int32 remainder;
436 
437  num /= 10;
438  remainder = oldval - num * 10;
439  start[minwidth] = '0' - remainder;
440  }
441  }
442  else
443  {
444  /* Build the number starting at the last digit */
445  while (minwidth--)
446  {
447  int32 oldval = num;
448  int32 remainder;
449 
450  num /= 10;
451  remainder = oldval - num * 10;
452  start[minwidth] = '0' + remainder;
453  }
454  }
455 
456  /*
457  * If minwidth was not high enough to fit the number then num won't have
458  * been divided down to zero. We punt the problem to pg_ltostr(), which
459  * will generate a correct answer in the minimum valid width.
460  */
461  if (num != 0)
462  return pg_ltostr(str, value);
463 
464  /* Otherwise, return last output character + 1 */
465  return end;
466 }
static struct @130 value
signed int int32
Definition: c.h:346
char * pg_ltostr(char *str, int32 value)
Definition: numutils.c:487
#define Assert(condition)
Definition: c.h:732

◆ pg_strtoint16()

int16 pg_strtoint16 ( const char *  s)

Definition at line 123 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().

124 {
125  const char *ptr = s;
126  int16 tmp = 0;
127  bool neg = false;
128 
129  /* skip leading spaces */
130  while (likely(*ptr) && isspace((unsigned char) *ptr))
131  ptr++;
132 
133  /* handle sign */
134  if (*ptr == '-')
135  {
136  ptr++;
137  neg = true;
138  }
139  else if (*ptr == '+')
140  ptr++;
141 
142  /* require at least one digit */
143  if (unlikely(!isdigit((unsigned char) *ptr)))
144  goto invalid_syntax;
145 
146  /* process digits */
147  while (*ptr && isdigit((unsigned char) *ptr))
148  {
149  int8 digit = (*ptr++ - '0');
150 
151  if (unlikely(pg_mul_s16_overflow(tmp, 10, &tmp)) ||
152  unlikely(pg_sub_s16_overflow(tmp, digit, &tmp)))
153  goto out_of_range;
154  }
155 
156  /* allow trailing whitespace, but not other trailing chars */
157  while (*ptr != '\0' && isspace((unsigned char) *ptr))
158  ptr++;
159 
160  if (unlikely(*ptr != '\0'))
161  goto invalid_syntax;
162 
163  if (!neg)
164  {
165  /* could fail if input is most negative number */
166  if (unlikely(tmp == PG_INT16_MIN))
167  goto out_of_range;
168  tmp = -tmp;
169  }
170 
171  return tmp;
172 
173 out_of_range:
174  ereport(ERROR,
175  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
176  errmsg("value \"%s\" is out of range for type %s",
177  s, "smallint")));
178 
179 invalid_syntax:
180  ereport(ERROR,
181  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
182  errmsg("invalid input syntax for type %s: \"%s\"",
183  "smallint", s)));
184 
185  return 0; /* keep compiler quiet */
186 }
signed short int16
Definition: c.h:345
#define likely(x)
Definition: c.h:207
int errcode(int sqlerrcode)
Definition: elog.c:570
static bool pg_mul_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:75
#define ERROR
Definition: elog.h:43
#define PG_INT16_MIN
Definition: c.h:437
#define ereport(elevel, rest)
Definition: elog.h:141
signed char int8
Definition: c.h:344
static bool pg_sub_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:52
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define unlikely(x)
Definition: c.h:208

◆ pg_strtoint32()

int32 pg_strtoint32 ( const char *  s)

Definition at line 199 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().

200 {
201  const char *ptr = s;
202  int32 tmp = 0;
203  bool neg = false;
204 
205  /* skip leading spaces */
206  while (likely(*ptr) && isspace((unsigned char) *ptr))
207  ptr++;
208 
209  /* handle sign */
210  if (*ptr == '-')
211  {
212  ptr++;
213  neg = true;
214  }
215  else if (*ptr == '+')
216  ptr++;
217 
218  /* require at least one digit */
219  if (unlikely(!isdigit((unsigned char) *ptr)))
220  goto invalid_syntax;
221 
222  /* process digits */
223  while (*ptr && isdigit((unsigned char) *ptr))
224  {
225  int8 digit = (*ptr++ - '0');
226 
227  if (unlikely(pg_mul_s32_overflow(tmp, 10, &tmp)) ||
228  unlikely(pg_sub_s32_overflow(tmp, digit, &tmp)))
229  goto out_of_range;
230  }
231 
232  /* allow trailing whitespace, but not other trailing chars */
233  while (*ptr != '\0' && isspace((unsigned char) *ptr))
234  ptr++;
235 
236  if (unlikely(*ptr != '\0'))
237  goto invalid_syntax;
238 
239  if (!neg)
240  {
241  /* could fail if input is most negative number */
242  if (unlikely(tmp == PG_INT32_MIN))
243  goto out_of_range;
244  tmp = -tmp;
245  }
246 
247  return tmp;
248 
249 out_of_range:
250  ereport(ERROR,
251  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
252  errmsg("value \"%s\" is out of range for type %s",
253  s, "integer")));
254 
255 invalid_syntax:
256  ereport(ERROR,
257  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
258  errmsg("invalid input syntax for type %s: \"%s\"",
259  "integer", s)));
260 
261  return 0; /* keep compiler quiet */
262 }
#define likely(x)
Definition: c.h:207
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:144
int errcode(int sqlerrcode)
Definition: elog.c:570
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:121
#define PG_INT32_MIN
Definition: c.h:440
#define ereport(elevel, rest)
Definition: elog.h:141
signed char int8
Definition: c.h:344
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define unlikely(x)
Definition: c.h:208

◆ pg_strtouint64()

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

Definition at line 558 of file numutils.c.

Referenced by _SPI_execute_plan(), and pgss_ProcessUtility().

559 {
560 #ifdef _MSC_VER /* MSVC only */
561  return _strtoui64(str, endptr, base);
562 #elif defined(HAVE_STRTOULL) && SIZEOF_LONG < 8
563  return strtoull(str, endptr, base);
564 #else
565  return strtoul(str, endptr, base);
566 #endif
567 }

◆ quote_identifier()

const char* quote_identifier ( const char *  ident)

Definition at line 10554 of file ruleutils.c.

References ScanKeyword::category, NumScanKeywords, palloc(), pg_malloc(), quote_all_identifiers, ScanKeywordLookup(), ScanKeywords, and UNRESERVED_KEYWORD.

Referenced by add_cast_to(), appendFunctionName(), ATPrepAlterColumnType(), ConvertTriggerToFK(), decompile_column_index_array(), deparseAnalyzeSql(), deparseColumnRef(), deparseOperatorName(), deparseRelation(), DropSubscription(), execute_extension_script(), explain_get_index_name(), ExplainTargetRel(), flatten_reloptions(), 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_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(), postgresGetForeignRelSize(), 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().

10555 {
10556  /*
10557  * Can avoid quoting if ident starts with a lowercase letter or underscore
10558  * and contains only lowercase letters, digits, and underscores, *and* is
10559  * not any SQL keyword. Otherwise, supply quotes.
10560  */
10561  int nquotes = 0;
10562  bool safe;
10563  const char *ptr;
10564  char *result;
10565  char *optr;
10566 
10567  /*
10568  * would like to use <ctype.h> macros here, but they might yield unwanted
10569  * locale-specific results...
10570  */
10571  safe = ((ident[0] >= 'a' && ident[0] <= 'z') || ident[0] == '_');
10572 
10573  for (ptr = ident; *ptr; ptr++)
10574  {
10575  char ch = *ptr;
10576 
10577  if ((ch >= 'a' && ch <= 'z') ||
10578  (ch >= '0' && ch <= '9') ||
10579  (ch == '_'))
10580  {
10581  /* okay */
10582  }
10583  else
10584  {
10585  safe = false;
10586  if (ch == '"')
10587  nquotes++;
10588  }
10589  }
10590 
10592  safe = false;
10593 
10594  if (safe)
10595  {
10596  /*
10597  * Check for keyword. We quote keywords except for unreserved ones.
10598  * (In some cases we could avoid quoting a col_name or type_func_name
10599  * keyword, but it seems much harder than it's worth to tell that.)
10600  *
10601  * Note: ScanKeywordLookup() does case-insensitive comparison, but
10602  * that's fine, since we already know we have all-lower-case.
10603  */
10604  const ScanKeyword *keyword = ScanKeywordLookup(ident,
10605  ScanKeywords,
10606  NumScanKeywords);
10607 
10608  if (keyword != NULL && keyword->category != UNRESERVED_KEYWORD)
10609  safe = false;
10610  }
10611 
10612  if (safe)
10613  return ident; /* no change needed */
10614 
10615  result = (char *) palloc(strlen(ident) + nquotes + 2 + 1);
10616 
10617  optr = result;
10618  *optr++ = '"';
10619  for (ptr = ident; *ptr; ptr++)
10620  {
10621  char ch = *ptr;
10622 
10623  if (ch == '"')
10624  *optr++ = '"';
10625  *optr++ = ch;
10626  }
10627  *optr++ = '"';
10628  *optr = '\0';
10629 
10630  return result;
10631 }
const ScanKeyword * ScanKeywordLookup(const char *text, const ScanKeyword *keywords, int num_keywords)
Definition: keywords.c:64
const int NumScanKeywords
Definition: keywords.c:45
#define UNRESERVED_KEYWORD
Definition: keywords.h:18
const ScanKeyword ScanKeywords[]
Definition: keywords.c:41
bool quote_all_identifiers
Definition: ruleutils.c:301
int16 category
Definition: keywords.h:28
void * palloc(Size size)
Definition: mcxt.c:924

◆ 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:924

◆ quote_qualified_identifier()

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

Definition at line 10640 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(), regconfigout(), regdictionaryout(), regprocout(), sepgsql_proc_post_create(), and transformColumnDefinition().

10642 {
10644 
10645  initStringInfo(&buf);
10646  if (qualifier)
10647  appendStringInfo(&buf, "%s.", quote_identifier(qualifier));
10649  return buf.data;
10650 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10554
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:163
static char * buf
Definition: pg_test_fsync.c:67
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46

◆ regexp_fixed_prefix()

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

Definition at line 1380 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().

1382 {
1383  char *result;
1384  regex_t *re;
1385  int cflags;
1386  int re_result;
1387  pg_wchar *str;
1388  size_t slen;
1389  size_t maxlen;
1390  char errMsg[100];
1391 
1392  *exact = false; /* default result */
1393 
1394  /* Compile RE */
1395  cflags = REG_ADVANCED;
1396  if (case_insensitive)
1397  cflags |= REG_ICASE;
1398 
1399  re = RE_compile_and_cache(text_re, cflags, collation);
1400 
1401  /* Examine it to see if there's a fixed prefix */
1402  re_result = pg_regprefix(re, &str, &slen);
1403 
1404  switch (re_result)
1405  {
1406  case REG_NOMATCH:
1407  return NULL;
1408 
1409  case REG_PREFIX:
1410  /* continue with wchar conversion */
1411  break;
1412 
1413  case REG_EXACT:
1414  *exact = true;
1415  /* continue with wchar conversion */
1416  break;
1417 
1418  default:
1419  /* re failed??? */
1421  pg_regerror(re_result, re, errMsg, sizeof(errMsg));
1422  ereport(ERROR,
1423  (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
1424  errmsg("regular expression failed: %s", errMsg)));
1425  break;
1426  }
1427 
1428  /* Convert pg_wchar result back to database encoding */
1429  maxlen = pg_database_encoding_max_length() * slen + 1;
1430  result = (char *) palloc(maxlen);
1431  slen = pg_wchar2mb_with_len(str, result, slen);
1432  Assert(slen < maxlen);
1433 
1434  free(str);
1435 
1436  return result;
1437 }
int errcode(int sqlerrcode)
Definition: elog.c:570
#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
int pg_database_encoding_max_length(void)
Definition: wchar.c:1833
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
#define ereport(elevel, rest)
Definition: elog.h:141
unsigned int pg_wchar
Definition: mbprint.c:31
static regex_t * RE_compile_and_cache(text *text_re, int cflags, Oid collation)
Definition: regexp.c:137
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:732
#define REG_EXACT
Definition: regex.h:163
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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:745
Definition: regex.h:55

◆ text_to_cstring()

char* text_to_cstring ( const text t)

Definition at line 182 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(), 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(), ltree_addtext(), ltree_textadd(), NUM_cache(), 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(), 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_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(), websearch_to_tsquery_byid(), X509_NAME_field_to_text(), xml_is_document(), xml_out_internal(), xmlconcat(), xmlpi(), xmlroot(), XmlTableGetValue(), xpath_table(), and xslt_process().

183 {
184  /* must cast away the const, unfortunately */
185  text *tunpacked = pg_detoast_datum_packed(unconstify(text *, t));
186  int len = VARSIZE_ANY_EXHDR(tunpacked);
187  char *result;
188 
189  result = (char *) palloc(len + 1);
190  memcpy(result, VARDATA_ANY(tunpacked), len);
191  result[len] = '\0';
192 
193  if (tunpacked != t)
194  pfree(tunpacked);
195 
196  return result;
197 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
void pfree(void *pointer)
Definition: mcxt.c:1031
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
Definition: fmgr.c:1949
#define unconstify(underlying_type, expr)
Definition: c.h:1145
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
void * palloc(Size size)
Definition: mcxt.c:924
Definition: c.h:549

◆ text_to_cstring_buffer()

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

Definition at line 213 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().

214 {
215  /* must cast away the const, unfortunately */
216  text *srcunpacked = pg_detoast_datum_packed(unconstify(text *, src));
217  size_t src_len = VARSIZE_ANY_EXHDR(srcunpacked);
218 
219  if (dst_len > 0)
220  {
221  dst_len--;
222  if (dst_len >= src_len)
223  dst_len = src_len;
224  else /* ensure truncation is encoding-safe */
225  dst_len = pg_mbcliplen(VARDATA_ANY(srcunpacked), src_len, dst_len);
226  memcpy(dst, VARDATA_ANY(srcunpacked), dst_len);
227  dst[dst_len] = '\0';
228  }
229 
230  if (srcunpacked != src)
231  pfree(srcunpacked);
232 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
void pfree(void *pointer)
Definition: mcxt.c:1031
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
Definition: fmgr.c:1949
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:820
#define unconstify(underlying_type, expr)
Definition: c.h:1145
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
Definition: c.h:549

◆ type_maximum_size()

int32 type_maximum_size ( Oid  type_oid,
int32  typemod 
)

Definition at line 397 of file format_type.c.

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

Referenced by get_typavgwidth(), and needs_toast_table().

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

◆ 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:507

Variable Documentation

◆ quote_all_identifiers

bool quote_all_identifiers

Definition at line 301 of file ruleutils.c.

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