PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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))
 

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, Name 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)
 
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)
 
double get_float8_infinity (void)
 
float get_float4_infinity (void)
 
double get_float8_nan (void)
 
float get_float4_nan (void)
 
int is_infinite (double val)
 
double float8in_internal (char *num, char **endptr_p, const char *type_name, const char *orig_string)
 
char * float8out_internal (double num)
 
int float4_cmp_internal (float4 a, float4 b)
 
int float8_cmp_internal (float8 a, float8 b)
 
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)
 
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)
 
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_be (Oid type_oid)
 
char * format_type_be_qualified (Oid type_oid)
 
char * format_type_with_typemod (Oid type_oid, int32 typemod)
 
char * format_type_with_typemod_qualified (Oid type_oid, int32 typemod)
 
int32 type_maximum_size (Oid type_oid, int32 typemod)
 
char * quote_literal_cstr (const char *rawstr)
 

Variables

PGDLLIMPORT int extra_float_digits
 
bool quote_all_identifiers
 

Macro Definition Documentation

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

Definition at line 91 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(), 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_build_array(), jsonb_build_object(), jsonb_object_keys(), page_header(), parse_ident(), pg_available_extensions(), pg_control_checkpoint(), pg_create_logical_replication_slot(), 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_exec_trigger(), ProcedureCreate(), publicationListToArray(), replorigin_by_name(), replorigin_create(), SetSecurityLabel(), SetSharedSecurityLabel(), ssl_extension_info(), StartReplication(), StoreAttrDefault(), StorePartitionBound(), StorePartitionKey(), string_to_datum(), strlist_to_textarray(), timetravel(), ts_lexize(), ttdummy(), TypeCreate(), UpdateIndexRelation(), and VXIDGetDatum().

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

Definition at line 92 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(), 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(), 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(), textarray_to_stringlist(), textarray_to_strvaluelist(), textout(), tfuncInitialize(), untransformRelOptions(), validateCheckConstraint(), and varcharout().

Function Documentation

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
int2vector* buildint2vector ( const int16 int2s,
int  n 
)

Definition at line 112 of file int.c.

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

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

113 {
114  int2vector *result;
115 
116  result = (int2vector *) palloc0(Int2VectorSize(n));
117 
118  if (n > 0 && int2s)
119  memcpy(result->values, int2s, n * sizeof(int16));
120 
121  /*
122  * Attach standard array header. For historical reasons, we set the index
123  * lower bound to 0 not 1.
124  */
125  SET_VARSIZE(result, Int2VectorSize(n));
126  result->ndim = 1;
127  result->dataoffset = 0; /* never any nulls */
128  result->elemtype = INT2OID;
129  result->dim1 = n;
130  result->lbound1 = 0;
131 
132  return result;
133 }
signed short int16
Definition: c.h:245
int lbound1
Definition: c.h:468
Oid elemtype
Definition: c.h:466
int32 dataoffset
Definition: c.h:465
#define INT2OID
Definition: pg_type.h:308
int ndim
Definition: c.h:464
Definition: c.h:461
void * palloc0(Size size)
Definition: mcxt.c:877
int dim1
Definition: c.h:467
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:469
#define Int2VectorSize(n)
Definition: int.c:43
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
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, OIDOID, 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:472
#define OIDOID
Definition: pg_type.h:328
int32 dataoffset
Definition: c.h:476
unsigned int Oid
Definition: postgres_ext.h:31
#define OidVectorSize(n)
Definition: oid.c:27
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:480
int dim1
Definition: c.h:478
void * palloc0(Size size)
Definition: mcxt.c:877
int lbound1
Definition: c.h:479
Oid elemtype
Definition: c.h:477
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
int ndim
Definition: c.h:475
void clean_ipv6_addr ( int  addr_family,
char *  addr 
)

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

1515 {
1516 #ifdef HAVE_IPV6
1517  if (addr_family == AF_INET6)
1518  {
1519  char *pct = strchr(addr, '%');
1520 
1521  if (pct)
1522  *pct = '\0';
1523  }
1524 #endif
1525 }
double convert_network_to_scalar ( Datum  value,
Oid  typid 
)

Definition at line 907 of file network.c.

References macaddr::a, macaddr8::a, macaddr::b, macaddr8::b, macaddr::c, macaddr8::c, CIDROID, macaddr::d, macaddr8::d, DatumGetInetPP, DatumGetMacaddr8P, DatumGetMacaddrP, macaddr::e, macaddr8::e, elog, ERROR, macaddr::f, macaddr8::f, macaddr8::g, macaddr8::h, i, INETOID, ip_addr, ip_family, MACADDR8OID, MACADDROID, and PGSQL_AF_INET.

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

908 {
909  switch (typid)
910  {
911  case INETOID:
912  case CIDROID:
913  {
914  inet *ip = DatumGetInetPP(value);
915  int len;
916  double res;
917  int i;
918 
919  /*
920  * Note that we don't use the full address for IPv6.
921  */
922  if (ip_family(ip) == PGSQL_AF_INET)
923  len = 4;
924  else
925  len = 5;
926 
927  res = ip_family(ip);
928  for (i = 0; i < len; i++)
929  {
930  res *= 256;
931  res += ip_addr(ip)[i];
932  }
933  return res;
934 
935  break;
936  }
937  case MACADDROID:
938  {
940  double res;
941 
942  res = (mac->a << 16) | (mac->b << 8) | (mac->c);
943  res *= 256 * 256 * 256;
944  res += (mac->d << 16) | (mac->e << 8) | (mac->f);
945  return res;
946  }
947  case MACADDR8OID:
948  {
950  double res;
951 
952  res = (mac->a << 24) | (mac->b << 16) | (mac->c << 8) | (mac->d);
953  res *= ((double) 256) * 256 * 256 * 256;
954  res += (mac->e << 24) | (mac->f << 16) | (mac->g << 8) | (mac->h);
955  return res;
956  }
957  }
958 
959  /*
960  * Can't get here unless someone tries to use scalarineqsel() on an
961  * operator with one network and one non-network operand.
962  */
963  elog(ERROR, "unsupported type: %u", typid);
964  return 0;
965 }
#define CIDROID
Definition: pg_type.h:451
#define DatumGetMacaddrP(X)
Definition: inet.h:131
#define ip_family(inetptr)
Definition: inet.h:71
#define PGSQL_AF_INET
Definition: inet.h:39
#define INETOID
Definition: pg_type.h:448
#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
#define ERROR
Definition: elog.h:43
unsigned char a
Definition: inet.h:96
Definition: inet.h:107
static struct @121 value
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
#define MACADDR8OID
Definition: pg_type.h:454
unsigned char d
Definition: inet.h:112
int i
#define MACADDROID
Definition: pg_type.h:445
#define elog
Definition: elog.h:219
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(), 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
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(), compute_tsvector_stats(), concat_internal(), cstring_to_text(), 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:303
#define VARHDRSZ
Definition: c.h:439
void * palloc(Size size)
Definition: mcxt.c:848
Definition: c.h:433
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:328
void domain_check ( Datum  value,
bool  isnull,
Oid  domainType,
void **  extra,
MemoryContext  mcxt 
)

Definition at line 326 of file domains.c.

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

Referenced by PLyObject_ToBool(), PLyObject_ToBytea(), PLySequence_ToArray(), and populate_domain().

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

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

360 {
361  HeapTuple tup;
362  Form_pg_type typtup;
363 
364  tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(datatypeOid));
365  if (!HeapTupleIsValid(tup))
366  elog(ERROR, "cache lookup failed for type %u", datatypeOid);
367  typtup = (Form_pg_type) GETSTRUCT(tup);
368 
370  get_namespace_name(typtup->typnamespace));
372 
373  ReleaseSysCache(tup);
374 
375  return 0; /* return value does not matter */
376 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define PG_DIAG_SCHEMA_NAME
Definition: postgres_ext.h:65
FormData_pg_type * Form_pg_type
Definition: pg_type.h:233
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3033
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:77
#define NameStr(name)
Definition: c.h:493
#define elog
Definition: elog.h:219
int err_generic_string(int field, const char *str)
Definition: elog.c:1191
int errdomainconstraint ( Oid  datatypeOid,
const char *  conname 
)

Definition at line 383 of file domains.c.

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

Referenced by domain_check_input(), and ExecEvalConstraintCheck().

384 {
385  errdatatype(datatypeOid);
387 
388  return 0; /* return value does not matter */
389 }
int errdatatype(Oid datatypeOid)
Definition: domains.c:359
#define PG_DIAG_CONSTRAINT_NAME
Definition: postgres_ext.h:69
int err_generic_string(int field, const char *str)
Definition: elog.c:1191
int float4_cmp_internal ( float4  a,
float4  b 
)

Definition at line 938 of file float.c.

Referenced by btfloat4cmp(), btfloat4fastcmp(), float4eq(), float4ge(), float4gt(), float4larger(), float4le(), float4lt(), float4ne(), and float4smaller().

939 {
940  /*
941  * We consider all NANs to be equal and larger than any non-NAN. This is
942  * somewhat arbitrary; the important thing is to have a consistent sort
943  * order.
944  */
945  if (isnan(a))
946  {
947  if (isnan(b))
948  return 0; /* NAN = NAN */
949  else
950  return 1; /* NAN > non-NAN */
951  }
952  else if (isnan(b))
953  {
954  return -1; /* non-NAN < NAN */
955  }
956  else
957  {
958  if (a > b)
959  return 1;
960  else if (a < b)
961  return -1;
962  else
963  return 0;
964  }
965 }
int float8_cmp_internal ( float8  a,
float8  b 
)

Definition at line 1052 of file float.c.

Referenced by btfloat48cmp(), btfloat84cmp(), btfloat8cmp(), btfloat8fastcmp(), float48eq(), float48ge(), float48gt(), float48le(), float48lt(), float48ne(), float84eq(), float84ge(), float84gt(), float84le(), float84lt(), float84ne(), float8eq(), float8ge(), float8gt(), float8larger(), float8le(), float8lt(), float8ne(), float8smaller(), interval_cmp_lower(), and interval_cmp_upper().

1053 {
1054  /*
1055  * We consider all NANs to be equal and larger than any non-NAN. This is
1056  * somewhat arbitrary; the important thing is to have a consistent sort
1057  * order.
1058  */
1059  if (isnan(a))
1060  {
1061  if (isnan(b))
1062  return 0; /* NAN = NAN */
1063  else
1064  return 1; /* NAN > non-NAN */
1065  }
1066  else if (isnan(b))
1067  {
1068  return -1; /* non-NAN < NAN */
1069  }
1070  else
1071  {
1072  if (a > b)
1073  return 1;
1074  else if (a < b)
1075  return -1;
1076  else
1077  return 0;
1078  }
1079 }
double float8in_internal ( char *  num,
char **  endptr_p,
const char *  type_name,
const char *  orig_string 
)

Definition at line 444 of file float.c.

References ereport, errcode(), errmsg(), ERROR, get_float8_infinity(), get_float8_nan(), pg_strncasecmp(), pstrdup(), and val.

Referenced by float8in(), pair_decode(), and single_decode().

446 {
447  double val;
448  char *endptr;
449 
450  /* skip leading whitespace */
451  while (*num != '\0' && isspace((unsigned char) *num))
452  num++;
453 
454  /*
455  * Check for an empty-string input to begin with, to avoid the vagaries of
456  * strtod() on different platforms.
457  */
458  if (*num == '\0')
459  ereport(ERROR,
460  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
461  errmsg("invalid input syntax for type %s: \"%s\"",
462  type_name, orig_string)));
463 
464  errno = 0;
465  val = strtod(num, &endptr);
466 
467  /* did we not see anything that looks like a double? */
468  if (endptr == num || errno != 0)
469  {
470  int save_errno = errno;
471 
472  /*
473  * C99 requires that strtod() accept NaN, [+-]Infinity, and [+-]Inf,
474  * but not all platforms support all of these (and some accept them
475  * but set ERANGE anyway...) Therefore, we check for these inputs
476  * ourselves if strtod() fails.
477  *
478  * Note: C99 also requires hexadecimal input as well as some extended
479  * forms of NaN, but we consider these forms unportable and don't try
480  * to support them. You can use 'em if your strtod() takes 'em.
481  */
482  if (pg_strncasecmp(num, "NaN", 3) == 0)
483  {
484  val = get_float8_nan();
485  endptr = num + 3;
486  }
487  else if (pg_strncasecmp(num, "Infinity", 8) == 0)
488  {
489  val = get_float8_infinity();
490  endptr = num + 8;
491  }
492  else if (pg_strncasecmp(num, "+Infinity", 9) == 0)
493  {
494  val = get_float8_infinity();
495  endptr = num + 9;
496  }
497  else if (pg_strncasecmp(num, "-Infinity", 9) == 0)
498  {
499  val = -get_float8_infinity();
500  endptr = num + 9;
501  }
502  else if (pg_strncasecmp(num, "inf", 3) == 0)
503  {
504  val = get_float8_infinity();
505  endptr = num + 3;
506  }
507  else if (pg_strncasecmp(num, "+inf", 4) == 0)
508  {
509  val = get_float8_infinity();
510  endptr = num + 4;
511  }
512  else if (pg_strncasecmp(num, "-inf", 4) == 0)
513  {
514  val = -get_float8_infinity();
515  endptr = num + 4;
516  }
517  else if (save_errno == ERANGE)
518  {
519  /*
520  * Some platforms return ERANGE for denormalized numbers (those
521  * that are not zero, but are too close to zero to have full
522  * precision). We'd prefer not to throw error for that, so try to
523  * detect whether it's a "real" out-of-range condition by checking
524  * to see if the result is zero or huge.
525  *
526  * On error, we intentionally complain about double precision not
527  * the given type name, and we print only the part of the string
528  * that is the current number.
529  */
530  if (val == 0.0 || val >= HUGE_VAL || val <= -HUGE_VAL)
531  {
532  char *errnumber = pstrdup(num);
533 
534  errnumber[endptr - num] = '\0';
535  ereport(ERROR,
536  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
537  errmsg("\"%s\" is out of range for type double precision",
538  errnumber)));
539  }
540  }
541  else
542  ereport(ERROR,
543  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
544  errmsg("invalid input syntax for type %s: \"%s\"",
545  type_name, orig_string)));
546  }
547 #ifdef HAVE_BUGGY_SOLARIS_STRTOD
548  else
549  {
550  /*
551  * Many versions of Solaris have a bug wherein strtod sets endptr to
552  * point one byte beyond the end of the string when given "inf" or
553  * "infinity".
554  */
555  if (endptr != num && endptr[-1] == '\0')
556  endptr--;
557  }
558 #endif /* HAVE_BUGGY_SOLARIS_STRTOD */
559 
560  /* skip trailing whitespace */
561  while (*endptr != '\0' && isspace((unsigned char) *endptr))
562  endptr++;
563 
564  /* report stopping point if wanted, else complain if not end of string */
565  if (endptr_p)
566  *endptr_p = endptr;
567  else if (*endptr != '\0')
568  ereport(ERROR,
569  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
570  errmsg("invalid input syntax for type %s: \"%s\"",
571  type_name, orig_string)));
572 
573  return val;
574 }
double get_float8_nan(void)
Definition: float.c:166
char * pstrdup(const char *in)
Definition: mcxt.c:1076
int errcode(int sqlerrcode)
Definition: elog.c:575
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
double get_float8_infinity(void)
Definition: float.c:121
int errmsg(const char *fmt,...)
Definition: elog.c:797
long val
Definition: informix.c:689
char* float8out_internal ( double  num)

Definition at line 596 of file float.c.

References ascii(), extra_float_digits, is_infinite(), MAXDOUBLEWIDTH, palloc(), and snprintf().

Referenced by cube_out(), float8out(), line_out(), pair_encode(), and single_encode().

597 {
598  char *ascii = (char *) palloc(MAXDOUBLEWIDTH + 1);
599 
600  if (isnan(num))
601  return strcpy(ascii, "NaN");
602 
603  switch (is_infinite(num))
604  {
605  case 1:
606  strcpy(ascii, "Infinity");
607  break;
608  case -1:
609  strcpy(ascii, "-Infinity");
610  break;
611  default:
612  {
613  int ndig = DBL_DIG + extra_float_digits;
614 
615  if (ndig < 1)
616  ndig = 1;
617 
618  snprintf(ascii, MAXDOUBLEWIDTH + 1, "%.*g", ndig, num);
619  }
620  }
621 
622  return ascii;
623 }
#define MAXDOUBLEWIDTH
Definition: float.c:48
Datum ascii(PG_FUNCTION_ARGS)
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
int extra_float_digits
Definition: float.c:68
int is_infinite(double val)
Definition: float.c:199
void * palloc(Size size)
Definition: mcxt.c:848
char* format_type_be ( Oid  type_oid)

Definition at line 94 of file format_type.c.

References format_type_internal().

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(), ATAddForeignKeyConstraint(), ATExecAlterColumnType(), ATExecSetStorage(), ATPrepAlterColumnType(), brinvalidate(), btvalidate(), build_column_default(), build_subplan(), check_object_ownership(), check_of_type(), 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_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(), lookup_rowtype_tupdesc_internal(), LookupTypeName(), 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_validator(), PLy_procedure_create(), prepare_sql_fn_parse_info(), print_function_arguments(), print_function_rettype(), print_function_trftypes(), ProcedureCreate(), processIndirection(), record_cmp(), record_eq(), record_image_cmp(), record_image_eq(), regtypeout(), RenameConstraintById(), RenameType(), resolve_generic_type(), ResolveOpClass(), ri_HashCompareOp(), select_common_type(), slot_store_error_callback(), spgvalidate(), storeOperators(), storeProcedures(), transformAggregateCall(), transformArrayExpr(), transformArraySubscripts(), transformArrayType(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformCollateClause(), transformColumnType(), transformPartitionBoundValue(), transformTypeCast(), transformXmlSerialize(), tuple_equals_slot(), tuple_to_stringinfo(), tupledesc_match(), unknown_attribute(), validateConnectbyTupleDesc(), variable_coerce_param_hook(), and width_bucket_array().

95 {
96  return format_type_internal(type_oid, -1, false, false, false);
97 }
static char * format_type_internal(Oid type_oid, int32 typemod, bool typemod_given, bool allow_invalid, bool force_qualify)
Definition: format_type.c:132
char* format_type_be_qualified ( Oid  type_oid)

Definition at line 104 of file format_type.c.

References format_type_internal().

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

105 {
106  return format_type_internal(type_oid, -1, false, false, true);
107 }
static char * format_type_internal(Oid type_oid, int32 typemod, bool typemod_given, bool allow_invalid, bool force_qualify)
Definition: format_type.c:132
char* format_type_with_typemod ( Oid  type_oid,
int32  typemod 
)

Definition at line 113 of file format_type.c.

References format_type_internal().

Referenced by analyzeCTE(), ATPrepAlterColumnType(), checkRuleResultList(), checkViewTupleDesc(), compatConnectbyTupleDescs(), convert_tuples_by_position(), deparse_type_name(), get_coercion_expr(), get_const_expr(), get_from_clause_coldeflist(), get_rule_expr(), get_rule_expr_funccall(), get_tablefunc(), get_variable(), and MergeAttributes().

114 {
115  return format_type_internal(type_oid, typemod, true, false, false);
116 }
static char * format_type_internal(Oid type_oid, int32 typemod, bool typemod_given, bool allow_invalid, bool force_qualify)
Definition: format_type.c:132
char* format_type_with_typemod_qualified ( Oid  type_oid,
int32  typemod 
)

Definition at line 123 of file format_type.c.

References format_type_internal().

Referenced by deparse_type_name().

124 {
125  return format_type_internal(type_oid, typemod, true, false, true);
126 }
static char * format_type_internal(Oid type_oid, int32 typemod, bool typemod_given, bool allow_invalid, bool force_qualify)
Definition: format_type.c:132
float get_float4_infinity ( void  )

Definition at line 146 of file float.c.

Referenced by float4in(), gistpenalty(), leftmostvalue_float4(), and range_gist_penalty().

147 {
148 #ifdef INFINITY
149  /* C99 standard way */
150  return (float) INFINITY;
151 #else
152 #if (_MSC_VER >= 1800)
153 #pragma warning(default:4756)
154 #endif
155 
156  /*
157  * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the
158  * largest normal double. We assume forcing an overflow will get us a
159  * true infinity.
160  */
161  return (float) (HUGE_VAL * HUGE_VAL);
162 #endif
163 }
float get_float4_nan ( void  )

Definition at line 179 of file float.c.

Referenced by float4in(), and numeric_float4().

180 {
181 #ifdef NAN
182  /* C99 standard way */
183  return (float) NAN;
184 #else
185  /* Assume we can get a NAN via zero divide */
186  return (float) (0.0 / 0.0);
187 #endif
188 }
double get_float8_infinity ( void  )

Definition at line 121 of file float.c.

Referenced by compute_range_stats(), dexp(), dpow(), float8in_internal(), gbt_ts_dist(), get_distance(), gistindex_keytest(), initRectBox(), leftmostvalue_float8(), NonFiniteTimestampTzPart(), pg_hypot(), and size_box().

122 {
123 #ifdef INFINITY
124  /* C99 standard way */
125  return (double) INFINITY;
126 #else
127 
128  /*
129  * On some platforms, HUGE_VAL is an infinity, elsewhere it's just the
130  * largest normal double. We assume forcing an overflow will get us a
131  * true infinity.
132  */
133  return (double) (HUGE_VAL * HUGE_VAL);
134 #endif
135 }
double get_float8_nan ( void  )

Definition at line 166 of file float.c.

Referenced by dacos(), dacosd(), dasin(), dasind(), datan(), datan2(), datan2d(), datand(), dcos(), dcosd(), dcot(), dcotd(), dsin(), dsind(), dtan(), dtand(), float8in_internal(), numeric_float8(), numeric_float8_no_overflow(), and pg_hypot().

167 {
168  /* (double) NAN doesn't work on some NetBSD/MIPS releases */
169 #if defined(NAN) && !(defined(__NetBSD__) && defined(__mips__))
170  /* C99 standard way */
171  return (double) NAN;
172 #else
173  /* Assume we can get a NAN via zero divide */
174  return (double) (0.0 / 0.0);
175 #endif
176 }
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:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
static char get_hex(char c)
Definition: encode.c:140
int errmsg(const char *fmt,...)
Definition: elog.c:797
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
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.h:289
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.h:289
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)
int is_infinite ( double  val)

Definition at line 199 of file float.c.

References isinf().

Referenced by calc_length_hist_frac(), float4_to_char(), float4out(), float8_to_char(), float8out_internal(), and get_len_position().

200 {
201  int inf = isinf(val);
202 
203  if (inf == 0)
204  return 0;
205  else if (val > 0)
206  return 1;
207  else
208  return -1;
209 }
int isinf(double x)
long val
Definition: informix.c:689
int namecpy ( Name  n1,
Name  n2 
)

Definition at line 191 of file name.c.

References NAMEDATALEN, NameStr, and StrNCpy.

Referenced by 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:836
#define NameStr(name)
Definition: c.h:493
int namestrcmp ( Name  name,
const char *  str 
)

Definition at line 247 of file name.c.

References NameStr.

Referenced by attnameAttNum(), CopyGetAttnums(), CreateTrigger(), get_timetravel(), GetAttributeByName(), set_timetravel(), 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:493
Datum network_scan_first ( Datum  in)

Definition at line 1101 of file network.c.

References DirectFunctionCall1, and network_network().

Referenced by network_prefix_quals().

1102 {
1104 }
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
Datum network_network(PG_FUNCTION_ARGS)
Definition: network.c:738
Datum network_scan_last ( Datum  in)

Definition at line 1115 of file network.c.

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

Referenced by network_prefix_quals().

1116 {
1119  Int32GetDatum(-1));
1120 }
Datum network_broadcast(PG_FUNCTION_ARGS)
Definition: network.c:693
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
Datum inet_set_masklen(PG_FUNCTION_ARGS)
Definition: network.c:283
#define Int32GetDatum(X)
Definition: postgres.h:485
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587
Datum numeric_float8_no_overflow ( PG_FUNCTION_ARGS  )

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

3194 {
3195  Numeric num = PG_GETARG_NUMERIC(0);
3196  double val;
3197 
3198  if (NUMERIC_IS_NAN(num))
3200 
3201  val = numeric_to_double_no_overflow(num);
3202 
3203  PG_RETURN_FLOAT8(val);
3204 }
double get_float8_nan(void)
Definition: float.c:166
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define PG_GETARG_NUMERIC(n)
Definition: numeric.h:52
static double numeric_to_double_no_overflow(Numeric num)
Definition: numeric.c:6402
#define NUMERIC_IS_NAN(n)
Definition: numeric.c:170
long val
Definition: informix.c:689
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
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:515
Definition: nodes.h:283
#define intVal(v)
Definition: value.h:52
#define elog
Definition: elog.h:219
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(), ProcessStartupPacket(), and readRecoveryCommandFile().

31 {
32  return parse_bool_with_len(value, strlen(value), result);
33 }
static struct @121 value
bool parse_bool_with_len(const char *value, size_t len, bool *result)
Definition: bool.c:36
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 @121 value
int32 pg_atoi ( const char *  s,
int  size,
int  c 
)

Definition at line 37 of file numutils.c.

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

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

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

Definition at line 120 of file numutils.c.

References pg_ltoa().

Referenced by int2out(), and int2vectorout().

121 {
122  pg_ltoa((int32) i, a);
123 }
signed int int32
Definition: c.h:246
int i
void pg_ltoa(int32 value, char *a)
Definition: numutils.c:132
void pg_lltoa ( int64  ll,
char *  a 
)

Definition at line 186 of file numutils.c.

References PG_INT64_MIN, swap, and value.

Referenced by int8out(), and printsimple().

187 {
188  char *start = a;
189  bool neg = false;
190 
191  /*
192  * Avoid problems with the most negative integer not being representable
193  * as a positive integer.
194  */
195  if (value == PG_INT64_MIN)
196  {
197  memcpy(a, "-9223372036854775808", 21);
198  return;
199  }
200  else if (value < 0)
201  {
202  value = -value;
203  neg = true;
204  }
205 
206  /* Compute the result string backwards. */
207  do
208  {
209  int64 remainder;
210  int64 oldval = value;
211 
212  value /= 10;
213  remainder = oldval - value * 10;
214  *a++ = '0' + remainder;
215  } while (value != 0);
216 
217  if (neg)
218  *a++ = '-';
219 
220  /* Add trailing NUL byte, and back up 'a' to the last character. */
221  *a-- = '\0';
222 
223  /* Reverse string. */
224  while (start < a)
225  {
226  char swap = *start;
227 
228  *start++ = *a;
229  *a-- = swap;
230  }
231 }
#define swap(a, b)
Definition: qsort.c:94
static struct @121 value
#define PG_INT64_MIN
Definition: c.h:327
void pg_ltoa ( int32  l,
char *  a 
)

Definition at line 132 of file numutils.c.

References PG_INT32_MIN, swap, and value.

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

133 {
134  char *start = a;
135  bool neg = false;
136 
137  /*
138  * Avoid problems with the most negative integer not being representable
139  * as a positive integer.
140  */
141  if (value == PG_INT32_MIN)
142  {
143  memcpy(a, "-2147483648", 12);
144  return;
145  }
146  else if (value < 0)
147  {
148  value = -value;
149  neg = true;
150  }
151 
152  /* Compute the result string backwards. */
153  do
154  {
155  int32 remainder;
156  int32 oldval = value;
157 
158  value /= 10;
159  remainder = oldval - value * 10;
160  *a++ = '0' + remainder;
161  } while (value != 0);
162 
163  if (neg)
164  *a++ = '-';
165 
166  /* Add trailing NUL byte, and back up 'a' to the last character. */
167  *a-- = '\0';
168 
169  /* Reverse string. */
170  while (start < a)
171  {
172  char swap = *start;
173 
174  *start++ = *a;
175  *a-- = swap;
176  }
177 }
#define swap(a, b)
Definition: qsort.c:94
signed int int32
Definition: c.h:246
static struct @121 value
#define PG_INT32_MIN
Definition: c.h:324
char* pg_ltostr ( char *  str,
int32  value 
)

Definition at line 334 of file numutils.c.

References swap, and value.

Referenced by AppendSeconds(), and pg_ltostr_zeropad().

335 {
336  char *start;
337  char *end;
338 
339  /*
340  * Handle negative numbers in a special way. We can't just write a '-'
341  * prefix and reverse the sign as that would overflow for INT32_MIN.
342  */
343  if (value < 0)
344  {
345  *str++ = '-';
346 
347  /* Mark the position we must reverse the string from. */
348  start = str;
349 
350  /* Compute the result string backwards. */
351  do
352  {
353  int32 oldval = value;
354  int32 remainder;
355 
356  value /= 10;
357  remainder = oldval - value * 10;
358  /* As above, we expect remainder to be negative. */
359  *str++ = '0' - remainder;
360  } while (value != 0);
361  }
362  else
363  {
364  /* Mark the position we must reverse the string from. */
365  start = str;
366 
367  /* Compute the result string backwards. */
368  do
369  {
370  int32 oldval = value;
371  int32 remainder;
372 
373  value /= 10;
374  remainder = oldval - value * 10;
375  *str++ = '0' + remainder;
376  } while (value != 0);
377  }
378 
379  /* Remember the end+1 and back up 'str' to the last character. */
380  end = str--;
381 
382  /* Reverse string. */
383  while (start < str)
384  {
385  char swap = *start;
386 
387  *start++ = *str;
388  *str-- = swap;
389  }
390 
391  return end;
392 }
#define swap(a, b)
Definition: qsort.c:94
signed int int32
Definition: c.h:246
static struct @121 value
char* pg_ltostr_zeropad ( char *  str,
int32  value,
int32  minwidth 
)

Definition at line 257 of file numutils.c.

References Assert, pg_ltostr(), and value.

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

258 {
259  char *start = str;
260  char *end = &str[minwidth];
261  int32 num = value;
262 
263  Assert(minwidth > 0);
264 
265  /*
266  * Handle negative numbers in a special way. We can't just write a '-'
267  * prefix and reverse the sign as that would overflow for INT32_MIN.
268  */
269  if (num < 0)
270  {
271  *start++ = '-';
272  minwidth--;
273 
274  /*
275  * Build the number starting at the last digit. Here remainder will
276  * be a negative number, so we must reverse the sign before adding '0'
277  * in order to get the correct ASCII digit.
278  */
279  while (minwidth--)
280  {
281  int32 oldval = num;
282  int32 remainder;
283 
284  num /= 10;
285  remainder = oldval - num * 10;
286  start[minwidth] = '0' - remainder;
287  }
288  }
289  else
290  {
291  /* Build the number starting at the last digit */
292  while (minwidth--)
293  {
294  int32 oldval = num;
295  int32 remainder;
296 
297  num /= 10;
298  remainder = oldval - num * 10;
299  start[minwidth] = '0' + remainder;
300  }
301  }
302 
303  /*
304  * If minwidth was not high enough to fit the number then num won't have
305  * been divided down to zero. We punt the problem to pg_ltostr(), which
306  * will generate a correct answer in the minimum valid width.
307  */
308  if (num != 0)
309  return pg_ltostr(str, value);
310 
311  /* Otherwise, return last output character + 1 */
312  return end;
313 }
signed int int32
Definition: c.h:246
static struct @121 value
char * pg_ltostr(char *str, int32 value)
Definition: numutils.c:334
#define Assert(condition)
Definition: c.h:681
uint64 pg_strtouint64 ( const char *  str,
char **  endptr,
int  base 
)

Definition at line 405 of file numutils.c.

Referenced by _SPI_execute_plan(), and pgss_ProcessUtility().

406 {
407 #ifdef _MSC_VER /* MSVC only */
408  return _strtoui64(str, endptr, base);
409 #elif defined(HAVE_STRTOULL) && SIZEOF_LONG < 8
410  return strtoull(str, endptr, base);
411 #else
412  return strtoul(str, endptr, base);
413 #endif
414 }
const char* quote_identifier ( const char *  ident)

Definition at line 10390 of file ruleutils.c.

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

Referenced by 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_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(), make_ruledef(), mv_GenerateOper(), 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(), refresh_by_match_merge(), regnamespaceout(), regoperout(), regroleout(), ri_add_cast_to(), ri_GenerateQual(), 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().

10391 {
10392  /*
10393  * Can avoid quoting if ident starts with a lowercase letter or underscore
10394  * and contains only lowercase letters, digits, and underscores, *and* is
10395  * not any SQL keyword. Otherwise, supply quotes.
10396  */
10397  int nquotes = 0;
10398  bool safe;
10399  const char *ptr;
10400  char *result;
10401  char *optr;
10402 
10403  /*
10404  * would like to use <ctype.h> macros here, but they might yield unwanted
10405  * locale-specific results...
10406  */
10407  safe = ((ident[0] >= 'a' && ident[0] <= 'z') || ident[0] == '_');
10408 
10409  for (ptr = ident; *ptr; ptr++)
10410  {
10411  char ch = *ptr;
10412 
10413  if ((ch >= 'a' && ch <= 'z') ||
10414  (ch >= '0' && ch <= '9') ||
10415  (ch == '_'))
10416  {
10417  /* okay */
10418  }
10419  else
10420  {
10421  safe = false;
10422  if (ch == '"')
10423  nquotes++;
10424  }
10425  }
10426 
10428  safe = false;
10429 
10430  if (safe)
10431  {
10432  /*
10433  * Check for keyword. We quote keywords except for unreserved ones.
10434  * (In some cases we could avoid quoting a col_name or type_func_name
10435  * keyword, but it seems much harder than it's worth to tell that.)
10436  *
10437  * Note: ScanKeywordLookup() does case-insensitive comparison, but
10438  * that's fine, since we already know we have all-lower-case.
10439  */
10440  const ScanKeyword *keyword = ScanKeywordLookup(ident,
10441  ScanKeywords,
10442  NumScanKeywords);
10443 
10444  if (keyword != NULL && keyword->category != UNRESERVED_KEYWORD)
10445  safe = false;
10446  }
10447 
10448  if (safe)
10449  return ident; /* no change needed */
10450 
10451  result = (char *) palloc(strlen(ident) + nquotes + 2 + 1);
10452 
10453  optr = result;
10454  *optr++ = '"';
10455  for (ptr = ident; *ptr; ptr++)
10456  {
10457  char ch = *ptr;
10458 
10459  if (ch == '"')
10460  *optr++ = '"';
10461  *optr++ = ch;
10462  }
10463  *optr++ = '"';
10464  *optr = '\0';
10465 
10466  return result;
10467 }
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:298
int16 category
Definition: keywords.h:28
void * palloc(Size size)
Definition: mcxt.c:848
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:848
char* quote_qualified_identifier ( const char *  qualifier,
const char *  ident 
)

Definition at line 10476 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_internal(), generate_collation_name(), generate_function_name(), generate_qualified_relation_name(), generate_relation_name(), getObjectDescription(), getObjectIdentityParts(), getOpFamilyDescription(), getOpFamilyIdentity(), getRelationDescription(), getRelationIdentity(), pg_decode_change(), 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().

10478 {
10480 
10481  initStringInfo(&buf);
10482  if (qualifier)
10483  appendStringInfo(&buf, "%s.", quote_identifier(qualifier));
10485  return buf.data;
10486 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10390
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
static char * buf
Definition: pg_test_fsync.c:67
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
char* regexp_fixed_prefix ( text text_re,
bool  case_insensitive,
Oid  collation,
bool exact 
)

Definition at line 1300 of file regexp.c.

References Assert, 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, and REG_PREFIX.

Referenced by regex_fixed_prefix().

1302 {
1303  char *result;
1304  regex_t *re;
1305  int cflags;
1306  int re_result;
1307  pg_wchar *str;
1308  size_t slen;
1309  size_t maxlen;
1310  char errMsg[100];
1311 
1312  *exact = false; /* default result */
1313 
1314  /* Compile RE */
1315  cflags = REG_ADVANCED;
1316  if (case_insensitive)
1317  cflags |= REG_ICASE;
1318 
1319  re = RE_compile_and_cache(text_re, cflags, collation);
1320 
1321  /* Examine it to see if there's a fixed prefix */
1322  re_result = pg_regprefix(re, &str, &slen);
1323 
1324  switch (re_result)
1325  {
1326  case REG_NOMATCH:
1327  return NULL;
1328 
1329  case REG_PREFIX:
1330  /* continue with wchar conversion */
1331  break;
1332 
1333  case REG_EXACT:
1334  *exact = true;
1335  /* continue with wchar conversion */
1336  break;
1337 
1338  default:
1339  /* re failed??? */
1341  pg_regerror(re_result, re, errMsg, sizeof(errMsg));
1342  ereport(ERROR,
1343  (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
1344  errmsg("regular expression failed: %s", errMsg)));
1345  break;
1346  }
1347 
1348  /* Convert pg_wchar result back to database encoding */
1349  maxlen = pg_database_encoding_max_length() * slen + 1;
1350  result = (char *) palloc(maxlen);
1351  slen = pg_wchar2mb_with_len(str, result, slen);
1352  Assert(slen < maxlen);
1353 
1354  free(str);
1355 
1356  return result;
1357 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#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:122
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:133
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:681
#define REG_EXACT
Definition: regex.h:163
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define REG_NOMATCH
Definition: regex.h:138
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:98
int pg_wchar2mb_with_len(const pg_wchar *from, char *to, int len)
Definition: mbutils.c:745
Definition: regex.h:55
char* text_to_cstring ( const text t)

Definition at line 182 of file varlena.c.

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

Referenced by array_to_text(), array_to_text_null(), binary_upgrade_create_empty_extension(), 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(), text2ltree(), text_concat_ws(), textToQualifiedNameList(), to_date(), to_regclass(), to_regnamespace(), to_regoper(), to_regoperator(), to_regproc(), to_regprocedure(), to_regrole(), to_regtype(), to_tsquery_byid(), transform_string_values_scalar(), ts_stat_sql(), tsquery_rewrite_query(), tuple_data_split(), X509_NAME_field_to_text(), xml_out_internal(), xmlconcat(), xmlpi(), xmlroot(), XmlTableGetValue(), and xpath_table().

183 {
184  /* must cast away the const, unfortunately */
185  text *tunpacked = pg_detoast_datum_packed((struct varlena *) 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:347
void pfree(void *pointer)
Definition: mcxt.c:949
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
Definition: fmgr.c:1858
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
void * palloc(Size size)
Definition: mcxt.c:848
Definition: c.h:433
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(), 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_zone(), and timetz_zone().

214 {
215  /* must cast away the const, unfortunately */
216  text *srcunpacked = pg_detoast_datum_packed((struct varlena *) 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:347
void pfree(void *pointer)
Definition: mcxt.c:949
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
Definition: fmgr.c:1858
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:820
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
Definition: c.h:433
int32 type_maximum_size ( Oid  type_oid,
int32  typemod 
)

Definition at line 389 of file format_type.c.

References BITOID, BITS_PER_BYTE, BPCHAROID, GetDatabaseEncoding(), numeric_maximum_size(), NUMERICOID, pg_encoding_max_length(), VARBITOID, VARCHAROID, and VARHDRSZ.

Referenced by get_typavgwidth(), and needs_toast_table().

390 {
391  if (typemod < 0)
392  return -1;
393 
394  switch (type_oid)
395  {
396  case BPCHAROID:
397  case VARCHAROID:
398  /* typemod includes varlena header */
399 
400  /* typemod is in characters not bytes */
401  return (typemod - VARHDRSZ) *
403  + VARHDRSZ;
404 
405  case NUMERICOID:
406  return numeric_maximum_size(typemod);
407 
408  case VARBITOID:
409  case BITOID:
410  /* typemod is the (max) number of bits */
411  return (typemod + (BITS_PER_BYTE - 1)) / BITS_PER_BYTE
412  + 2 * sizeof(int32);
413  }
414 
415  /* Unknown type, or unlimited-width type such as 'text' */
416  return -1;
417 }
#define BPCHAROID
Definition: pg_type.h:504
#define BITS_PER_BYTE
#define NUMERICOID
Definition: pg_type.h:554
#define VARHDRSZ
Definition: c.h:439
#define VARBITOID
Definition: pg_type.h:546
signed int int32
Definition: c.h:246
int pg_encoding_max_length(int encoding)
Definition: wchar.c:1820
#define VARCHAROID
Definition: pg_type.h:507
int GetDatabaseEncoding(void)
Definition: mbutils.c:1004
int32 numeric_maximum_size(int32 typmod)
Definition: numeric.c:690
#define BITOID
Definition: pg_type.h:542
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:391

Variable Documentation

PGDLLIMPORT int extra_float_digits

Definition at line 68 of file float.c.

Referenced by float4out(), float8out_internal(), and set_transmission_modes().

bool quote_all_identifiers

Definition at line 298 of file ruleutils.c.

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