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

Go to the source code of this file.

Macros

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

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)
 
bool domain_check_safe (Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt, Node *escontext)
 
int errdatatype (Oid datatypeOid)
 
int errdomainconstraint (Oid datatypeOid, const char *conname)
 
uint64 hex_encode (const char *src, size_t len, char *dst)
 
uint64 hex_decode (const char *src, size_t len, char *dst)
 
uint64 hex_decode_safe (const char *src, size_t len, char *dst, Node *escontext)
 
int2vectorbuildint2vector (const int16 *int2s, int n)
 
void namestrcpy (Name name, const char *str)
 
int namestrcmp (Name name, const char *str)
 
int16 pg_strtoint16 (const char *s)
 
int16 pg_strtoint16_safe (const char *s, Node *escontext)
 
int32 pg_strtoint32 (const char *s)
 
int32 pg_strtoint32_safe (const char *s, Node *escontext)
 
int64 pg_strtoint64 (const char *s)
 
int64 pg_strtoint64_safe (const char *s, Node *escontext)
 
uint32 uint32in_subr (const char *s, char **endloc, const char *typname, Node *escontext)
 
uint64 uint64in_subr (const char *s, char **endloc, const char *typname, Node *escontext)
 
int pg_itoa (int16 i, char *a)
 
int pg_ultoa_n (uint32 value, char *a)
 
int pg_ulltoa_n (uint64 value, char *a)
 
int pg_ltoa (int32 value, char *a)
 
int pg_lltoa (int64 value, char *a)
 
char * pg_ultostr_zeropad (char *str, uint32 value, int32 minwidth)
 
char * pg_ultostr (char *str, uint32 value)
 
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)
 
int xidLogicalComparator (const void *arg1, const void *arg2)
 
char * pg_inet_cidr_ntop (int af, const void *src, int bits, char *dst, size_t size)
 
int pg_inet_net_pton (int af, const char *src, void *dst, size_t size)
 
double convert_network_to_scalar (Datum value, Oid typid, bool *failure)
 
Datum network_scan_first (Datum in)
 
Datum network_scan_last (Datum in)
 
void clean_ipv6_addr (int addr_family, char *addr)
 
Datum numeric_float8_no_overflow (PG_FUNCTION_ARGS)
 
char * format_type_extended (Oid type_oid, int32 typemod, bits16 flags)
 
char * format_type_be (Oid type_oid)
 
char * format_type_be_qualified (Oid type_oid)
 
char * format_type_with_typemod (Oid type_oid, int32 typemod)
 
int32 type_maximum_size (Oid type_oid, int32 typemod)
 
char * quote_literal_cstr (const char *rawstr)
 

Variables

PGDLLIMPORT bool quote_all_identifiers
 

Macro Definition Documentation

◆ CStringGetTextDatum

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

Definition at line 97 of file builtins.h.

◆ FORMAT_TYPE_ALLOW_INVALID

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

Definition at line 125 of file builtins.h.

◆ FORMAT_TYPE_FORCE_QUALIFY

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

Definition at line 126 of file builtins.h.

◆ FORMAT_TYPE_INVALID_AS_NULL

#define FORMAT_TYPE_INVALID_AS_NULL   0x08 /* NULL if undefined */

Definition at line 127 of file builtins.h.

◆ FORMAT_TYPE_TYPEMOD_GIVEN

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

Definition at line 124 of file builtins.h.

◆ MAXINT8LEN

#define MAXINT8LEN   20

Definition at line 22 of file builtins.h.

◆ TextDatumGetCString

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

Definition at line 98 of file builtins.h.

Function Documentation

◆ bpchartruelen()

int bpchartruelen ( char *  s,
int  len 
)

Definition at line 676 of file varchar.c.

677{
678 int i;
679
680 /*
681 * Note that we rely on the assumption that ' ' is a singleton unit on
682 * every supported multibyte server encoding.
683 */
684 for (i = len - 1; i >= 0; i--)
685 {
686 if (s[i] != ' ')
687 break;
688 }
689 return i + 1;
690}
int i
Definition: isn.c:72
const void size_t len

References i, and len.

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

◆ buildint2vector()

int2vector * buildint2vector ( const int16 int2s,
int  n 
)

Definition at line 114 of file int.c.

115{
116 int2vector *result;
117
118 result = (int2vector *) palloc0(Int2VectorSize(n));
119
120 if (n > 0 && int2s)
121 memcpy(result->values, int2s, n * sizeof(int16));
122
123 /*
124 * Attach standard array header. For historical reasons, we set the index
125 * lower bound to 0 not 1.
126 */
127 SET_VARSIZE(result, Int2VectorSize(n));
128 result->ndim = 1;
129 result->dataoffset = 0; /* never any nulls */
130 result->elemtype = INT2OID;
131 result->dim1 = n;
132 result->lbound1 = 0;
133
134 return result;
135}
int16_t int16
Definition: c.h:480
#define Int2VectorSize(n)
Definition: int.c:45
void * palloc0(Size size)
Definition: mcxt.c:1347
Definition: c.h:669
int ndim
Definition: c.h:671
int dim1
Definition: c.h:674
Oid elemtype
Definition: c.h:673
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:676
int32 dataoffset
Definition: c.h:672
int lbound1
Definition: c.h:675
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

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

Referenced by attnumstoint2vector(), CreateStatistics(), CreateTriggerFiringOn(), pg_get_publication_tables(), StorePartitionKey(), and UpdateIndexRelation().

◆ buildoidvector()

oidvector * buildoidvector ( const Oid oids,
int  n 
)

Definition at line 87 of file oid.c.

88{
89 oidvector *result;
90
91 result = (oidvector *) palloc0(OidVectorSize(n));
92
93 if (n > 0 && oids)
94 memcpy(result->values, oids, n * sizeof(Oid));
95
96 /*
97 * Attach standard array header. For historical reasons, we set the index
98 * lower bound to 0 not 1.
99 */
100 SET_VARSIZE(result, OidVectorSize(n));
101 result->ndim = 1;
102 result->dataoffset = 0; /* never any nulls */
103 result->elemtype = OIDOID;
104 result->dim1 = n;
105 result->lbound1 = 0;
106
107 return result;
108}
#define OidVectorSize(n)
Definition: oid.c:29
unsigned int Oid
Definition: postgres_ext.h:31
Definition: c.h:680
int dim1
Definition: c.h:685
int32 dataoffset
Definition: c.h:683
Oid elemtype
Definition: c.h:684
int lbound1
Definition: c.h:686
int ndim
Definition: c.h:682
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:687

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

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

◆ clean_ipv6_addr()

void clean_ipv6_addr ( int  addr_family,
char *  addr 
)

Definition at line 2089 of file network.c.

2090{
2091 if (addr_family == AF_INET6)
2092 {
2093 char *pct = strchr(addr, '%');
2094
2095 if (pct)
2096 *pct = '\0';
2097 }
2098}

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

◆ convert_network_to_scalar()

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

Definition at line 1496 of file network.c.

1497{
1498 switch (typid)
1499 {
1500 case INETOID:
1501 case CIDROID:
1502 {
1503 inet *ip = DatumGetInetPP(value);
1504 int len;
1505 double res;
1506 int i;
1507
1508 /*
1509 * Note that we don't use the full address for IPv6.
1510 */
1511 if (ip_family(ip) == PGSQL_AF_INET)
1512 len = 4;
1513 else
1514 len = 5;
1515
1516 res = ip_family(ip);
1517 for (i = 0; i < len; i++)
1518 {
1519 res *= 256;
1520 res += ip_addr(ip)[i];
1521 }
1522 return res;
1523 }
1524 case MACADDROID:
1525 {
1527 double res;
1528
1529 res = (mac->a << 16) | (mac->b << 8) | (mac->c);
1530 res *= 256 * 256 * 256;
1531 res += (mac->d << 16) | (mac->e << 8) | (mac->f);
1532 return res;
1533 }
1534 case MACADDR8OID:
1535 {
1537 double res;
1538
1539 res = (mac->a << 24) | (mac->b << 16) | (mac->c << 8) | (mac->d);
1540 res *= ((double) 256) * 256 * 256 * 256;
1541 res += (mac->e << 24) | (mac->f << 16) | (mac->g << 8) | (mac->h);
1542 return res;
1543 }
1544 }
1545
1546 *failure = true;
1547 return 0;
1548}
static struct @161 value
Definition: inet.h:53
Definition: inet.h:108
unsigned char c
Definition: inet.h:111
unsigned char b
Definition: inet.h:110
unsigned char d
Definition: inet.h:112
unsigned char e
Definition: inet.h:113
unsigned char g
Definition: inet.h:115
unsigned char h
Definition: inet.h:116
unsigned char a
Definition: inet.h:109
unsigned char f
Definition: inet.h:114
Definition: inet.h:95
unsigned char e
Definition: inet.h:100
unsigned char b
Definition: inet.h:97
unsigned char f
Definition: inet.h:101
unsigned char c
Definition: inet.h:98
unsigned char a
Definition: inet.h:96
unsigned char d
Definition: inet.h:99
static macaddr8 * DatumGetMacaddr8P(Datum X)
Definition: inet.h:163
static inet * DatumGetInetPP(Datum X)
Definition: inet.h:123
#define ip_addr(inetptr)
Definition: inet.h:77
#define ip_family(inetptr)
Definition: inet.h:71
static macaddr * DatumGetMacaddrP(Datum X)
Definition: inet.h:147
#define PGSQL_AF_INET
Definition: inet.h:39

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, len, PGSQL_AF_INET, res, and value.

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

◆ cstring_to_text()

text * cstring_to_text ( const char *  s)

Definition at line 184 of file varlena.c.

185{
186 return cstring_to_text_with_len(s, strlen(s));
187}
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:196

References cstring_to_text_with_len().

Referenced by array_dims(), ASN1_STRING_to_text(), booltext(), brin_minmax_multi_summary_out(), brin_page_type(), build_test_info_result(), build_test_match_result(), cidr_abbrev(), convert_charset(), cstring_to_xmltype(), current_query(), datetime_to_char_body(), dblink_build_sql_delete(), dblink_build_sql_insert(), dblink_build_sql_update(), dblink_cancel_query(), dblink_close(), dblink_connect(), dblink_disconnect(), dblink_error_message(), dblink_exec(), dblink_open(), dmetaphone(), dmetaphone_alt(), exec_assign_c_string(), executeDateTimeMethod(), filter_list_to_array(), format_type(), get_command_tag(), get_command_type(), get_scalar(), hash_page_type(), icu_unicode_version(), inet_abbrev(), initcap(), json_in(), json_typeof(), jsonb_get_element(), jsonb_typeof(), JsonbValueAsText(), lower(), md5_bytea(), md5_text(), metaphone(), name_bpchar(), name_text(), network_host(), network_show(), oidvectortypes(), ParameterAclCreate(), ParameterAclLookup(), pg_collation_actual_version(), pg_collation_for(), pg_column_compression(), pg_crypt(), pg_current_logfile(), pg_database_collation_actual_version(), pg_describe_object(), pg_export_snapshot(), pg_get_statisticsobjdef_expressions(), pg_get_wal_replay_pause_state(), pg_parameter_aclmask(), pg_relation_filepath(), pg_size_pretty(), pg_size_pretty_numeric(), pg_stat_get_backend_activity(), pg_stat_get_backend_wait_event(), pg_stat_get_backend_wait_event_type(), pg_stat_get_slru(), pg_stats_ext_mcvlist_items(), pg_tablespace_location(), pg_walfile_name(), pg_xact_status(), 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_part(), ssl_cipher(), ssl_client_dn(), ssl_issuer_dn(), ssl_version(), string_to_text(), test_canonicalize_path(), test_slru_page_read(), test_slru_page_readonly(), text_substring(), textin(), timeofday(), timetz_at_local(), tsquerytree(), unaccent_dict(), unicode_version(), upper(), xml_encode_special_chars(), xml_in(), and xml_recv().

◆ cstring_to_text_with_len()

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

Definition at line 196 of file varlena.c.

197{
198 text *result = (text *) palloc(len + VARHDRSZ);
199
200 SET_VARSIZE(result, len + VARHDRSZ);
201 memcpy(VARDATA(result), s, len);
202
203 return result;
204}
#define VARHDRSZ
Definition: c.h:646
void * palloc(Size size)
Definition: mcxt.c:1317
Definition: c.h:641
#define VARDATA(PTR)
Definition: varatt.h:278

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

Referenced by array_to_json(), array_to_json_pretty(), array_to_text_internal(), brin_minmax_multi_summary_out(), build_regexp_match_result(), build_regexp_split_result(), build_test_match_result(), cash_words(), compute_tsvector_stats(), concat_internal(), convert_to_base(), cstring_to_text(), daitch_mokotoff_coding(), datum_to_json(), do_text_output_multiline(), dotrim(), each_object_field_end(), each_worker_jsonb(), elements_array_element_end(), ExecEvalMergeSupportFunc(), ExecEvalXmlExpr(), executeDateTimeMethod(), executeLikeRegex(), find_or_create_child_node(), fsm_page_contents(), get_array_element_end(), get_array_end(), get_object_end(), get_object_field_end(), get_scalar(), gin_extract_tsquery(), gin_extract_tsvector(), hstore_akeys(), hstore_avals(), hstore_each(), hstore_fetchval(), hstore_skeys(), hstore_slice_to_array(), hstore_subscript_fetch(), hstore_svals(), hstore_to_array_internal(), hstore_to_json(), hstore_to_json_loose(), json_build_array_noargs(), json_build_array_worker(), json_build_object_noargs(), json_build_object_worker(), json_object(), json_object_two_arg(), json_recv(), json_strip_nulls(), jsonb_pretty(), JsonbValueAsText(), leftmostvalue_text(), LogicalOutputWrite(), parse_ident(), pg_gen_salt(), pg_gen_salt_rounds(), pg_get_function_sqlbody(), replace_text(), replace_text_regexp(), row_to_json(), row_to_json_pretty(), serialize_deflist(), split_part(), split_text(), ssl_extension_info(), string_agg_finalfn(), stringinfo_to_xmltype(), text_format(), text_left(), text_right(), textrecv(), transform_json_string_values(), tsquerytree(), tsvector_to_array(), tsvector_unnest(), unistr(), varchar(), varchar_input(), xmltext(), xmltotext_with_options(), and xslt_process().

◆ domain_check()

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

Definition at line 346 of file domains.c.

348{
349 (void) domain_check_internal(value, isnull, domainType, extra, mcxt,
350 NULL);
351}
static bool domain_check_internal(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt, Node *escontext)
Definition: domains.c:371

References domain_check_internal(), and value.

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(), and PLyObject_ToDomain().

◆ domain_check_safe()

bool domain_check_safe ( Datum  value,
bool  isnull,
Oid  domainType,
void **  extra,
MemoryContext  mcxt,
Node escontext 
)

Definition at line 355 of file domains.c.

358{
359 return domain_check_internal(value, isnull, domainType, extra, mcxt,
360 escontext);
361}

References domain_check_internal(), and value.

Referenced by ExecEvalJsonCoercion(), populate_composite(), populate_domain(), and populate_recordset_record().

◆ errdatatype()

int errdatatype ( Oid  datatypeOid)

Definition at line 407 of file domains.c.

408{
409 HeapTuple tup;
410 Form_pg_type typtup;
411
412 tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(datatypeOid));
413 if (!HeapTupleIsValid(tup))
414 elog(ERROR, "cache lookup failed for type %u", datatypeOid);
415 typtup = (Form_pg_type) GETSTRUCT(tup);
416
418 get_namespace_name(typtup->typnamespace));
420
421 ReleaseSysCache(tup);
422
423 return 0; /* return value does not matter */
424}
#define NameStr(name)
Definition: c.h:700
int err_generic_string(int field, const char *str)
Definition: elog.c:1512
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3366
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
#define PG_DIAG_SCHEMA_NAME
Definition: postgres_ext.h:64
#define PG_DIAG_DATATYPE_NAME
Definition: postgres_ext.h:67
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221

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

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

◆ errdomainconstraint()

int errdomainconstraint ( Oid  datatypeOid,
const char *  conname 
)

Definition at line 431 of file domains.c.

432{
433 errdatatype(datatypeOid);
435
436 return 0; /* return value does not matter */
437}
int errdatatype(Oid datatypeOid)
Definition: domains.c:407
#define PG_DIAG_CONSTRAINT_NAME
Definition: postgres_ext.h:68

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

Referenced by domain_check_input(), and ExecEvalConstraintCheck().

◆ format_type_be()

char * format_type_be ( Oid  type_oid)

Definition at line 343 of file format_type.c.

344{
345 return format_type_extended(type_oid, -1, 0);
346}
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
Definition: format_type.c:112

References format_type_extended().

Referenced by aclcheck_error_type(), addFamilyMember(), addRangeTableEntryForFunction(), AggregateCreate(), AlterType(), AlterTypeNamespace(), AlterTypeNamespace_oid(), AlterTypeNamespaceInternal(), AlterTypeOwner(), AlterTypeOwnerInternal(), analyzeCTE(), 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(), ATPrepAlterColumnType(), brinvalidate(), btvalidate(), build_attrmap_by_name(), build_column_default(), build_datatype(), build_subplan(), CastCreate(), check_object_ownership(), check_of_type(), check_safe_enum_use(), check_sql_fn_retval(), check_valid_polymorphic_signature(), CheckAttributeType(), checkDomainOwner(), checkEnumOwner(), checkRuleResultList(), CheckVarSlotCompatibility(), coerce_record_to_complex(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), coerce_type(), coerceJsonFuncExpr(), compare_values_of_enum(), compile_plperl_function(), compile_pltcl_function(), ComputeIndexAttrs(), ComputePartitionAttrs(), cookDefault(), create_ctas_nodata(), CreateCast(), CreateFunction(), CreateStatistics(), CreateTransform(), DefineAggregate(), DefineDomain(), DefineRange(), DefineType(), do_compile(), domain_check_input(), domain_state_setup(), dropOperators(), dropProcedures(), enforce_generic_type_consistency(), enum_first(), enum_in(), enum_last(), enum_recv(), EvaluateParams(), exec_stmt_foreach_a(), ExecAlterExtensionContentsRecurse(), ExecBuildUpdateProjection(), ExecCheckPlanOutput(), ExecEvalArrayExpr(), ExecEvalConstraintCheck(), ExecEvalConstraintNotNull(), ExecEvalFieldSelect(), ExecEvalParamExtern(), ExecEvalWholeRowVar(), ExecInitAgg(), ExecInitExprRec(), ExecInitSubscriptingRef(), exprType(), extract_date(), fetch_cursor_param_value(), findRangeSubOpclass(), findTypeInputFunction(), findTypeReceiveFunction(), fmgr_sql_validator(), format_operator_extended(), format_procedure_extended(), funcname_signature_string(), get_cached_rowtype(), get_cast_oid(), get_domain_constraint_oid(), get_expr_result_tupdesc(), get_multirange_io_data(), get_range_io_data(), get_rels_with_domain(), get_sort_group_operators(), get_transform_oid(), get_ts_parser_func(), get_ts_template_func(), GetAttributeCompression(), GetAttributeStorage(), GetColumnDefCollation(), GetDefaultOpClass(), getObjectDescription(), GetOperatorFromCompareType(), getTypeBinaryInputInfo(), getTypeBinaryOutputInfo(), getTypeInputInfo(), getTypeOutputInfo(), hash_array(), hash_array_extended(), hash_multirange(), hash_multirange_extended(), hash_range(), hash_range_extended(), hash_record(), hash_record_extended(), hashvalidate(), init_params(), initArrayResultArr(), initGinState(), internal_get_result_type(), interval_part_common(), interval_trunc(), intorel_startup(), jsonb_subscript_transform(), JsonItemFromDatum(), load_enum_cache_data(), lookup_rowtype_tupdesc_domain(), lookup_rowtype_tupdesc_internal(), LookupTypeNameExtended(), make_expanded_record_from_tupdesc(), make_expanded_record_from_typeid(), make_row_comparison_op(), make_scalar_array_op(), NonFiniteIntervalPart(), NonFiniteTimestampTzPart(), op_signature_string(), ParseFuncOrColumn(), pg_collation_for(), plperl_array_to_datum(), plperl_sv_to_datum(), plperl_validator(), plpgsql_build_datatype_arrayof(), plpgsql_build_variable(), plpgsql_param_eval_generic(), plpgsql_param_eval_generic_ro(), plpgsql_param_eval_recfield(), plpgsql_validator(), PLy_procedure_create(), prepare_sql_fn_parse_info(), print_function_arguments(), print_function_rettype(), print_function_trftypes(), processIndirection(), record_cmp(), record_eq(), record_image_cmp(), record_image_eq(), regtypeout(), RelationBuildPartitionKey(), RenameConstraintById(), RenameType(), resolve_anyarray_from_others(), resolve_anyelement_from_others(), resolve_anymultirange_from_others(), resolve_anyrange_from_others(), ResolveOpClass(), revalidate_rectypeid(), ri_HashCompareOp(), satisfies_hash_partition(), select_common_type(), select_common_type_from_oids(), spgvalidate(), stats_check_arg_type(), stats_fill_fcinfo_from_arg_pairs(), storeOperators(), storeProcedures(), time_part_common(), timestamp_part_common(), timestamp_trunc(), timestamptz_part_common(), timestamptz_trunc_internal(), timetz_part_common(), transformAggregateCall(), transformArrayExpr(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformCollateClause(), transformColumnType(), transformContainerSubscripts(), transformFrameOffset(), transformJsonBehavior(), transformJsonFuncExpr(), transformJsonIsPredicate(), transformJsonReturning(), transformJsonSerializeExpr(), transformJsonValueExpr(), transformPartitionBoundValue(), transformPLAssignStmt(), transformTypeCast(), transformXmlSerialize(), tuple_to_stringinfo(), tupledesc_match(), tuples_equal(), unknown_attribute(), validateConnectbyTupleDesc(), variable_coerce_param_hook(), and width_bucket_array().

◆ format_type_be_qualified()

char * format_type_be_qualified ( Oid  type_oid)

◆ format_type_extended()

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

Definition at line 112 of file format_type.c.

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

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

Referenced by array_recv(), deparse_type_name(), format_type(), format_type_be(), format_type_be_qualified(), format_type_with_typemod(), gbtreekey_in(), getObjectDescription(), getObjectIdentityParts(), lookup_am_handler_func(), oidvectortypes(), and record_recv().

◆ format_type_with_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 13285 of file ruleutils.c.

13289{
13290 HeapTuple opertup;
13291 Form_pg_operator operform;
13292 char *oprname;
13293 char *nspname;
13294
13295 opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(opoid));
13296 if (!HeapTupleIsValid(opertup))
13297 elog(ERROR, "cache lookup failed for operator %u", opoid);
13298 operform = (Form_pg_operator) GETSTRUCT(opertup);
13299 Assert(operform->oprkind == 'b');
13300 oprname = NameStr(operform->oprname);
13301
13302 nspname = get_namespace_name(operform->oprnamespace);
13303
13304 appendStringInfoString(buf, leftop);
13305 if (leftoptype != operform->oprleft)
13306 add_cast_to(buf, operform->oprleft);
13307 appendStringInfo(buf, " OPERATOR(%s.", quote_identifier(nspname));
13308 appendStringInfoString(buf, oprname);
13309 appendStringInfo(buf, ") %s", rightop);
13310 if (rightoptype != operform->oprright)
13311 add_cast_to(buf, operform->oprright);
13312
13313 ReleaseSysCache(opertup);
13314}
#define Assert(condition)
Definition: c.h:812
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
static void add_cast_to(StringInfo buf, Oid typid)
Definition: ruleutils.c:13325
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:12875
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230

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

Referenced by refresh_by_match_merge(), and ri_GenerateQual().

◆ hex_decode()

uint64 hex_decode ( const char *  src,
size_t  len,
char *  dst 
)

Definition at line 190 of file encode.c.

191{
192 return hex_decode_safe(src, len, dst, NULL);
193}
uint64 hex_decode_safe(const char *src, size_t len, char *dst, Node *escontext)
Definition: encode.c:196

References hex_decode_safe(), and len.

◆ hex_decode_safe()

uint64 hex_decode_safe ( const char *  src,
size_t  len,
char *  dst,
Node escontext 
)

Definition at line 196 of file encode.c.

197{
198 const char *s,
199 *srcend;
200 char v1,
201 v2,
202 *p;
203
204 srcend = src + len;
205 s = src;
206 p = dst;
207 while (s < srcend)
208 {
209 if (*s == ' ' || *s == '\n' || *s == '\t' || *s == '\r')
210 {
211 s++;
212 continue;
213 }
214 if (!get_hex(s, &v1))
215 ereturn(escontext, 0,
216 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
217 errmsg("invalid hexadecimal digit: \"%.*s\"",
218 pg_mblen(s), s)));
219 s++;
220 if (s >= srcend)
221 ereturn(escontext, 0,
222 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
223 errmsg("invalid hexadecimal data: odd number of digits")));
224 if (!get_hex(s, &v2))
225 ereturn(escontext, 0,
226 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
227 errmsg("invalid hexadecimal digit: \"%.*s\"",
228 pg_mblen(s), s)));
229 s++;
230 *p++ = (v1 << 4) | v2;
231 }
232
233 return p - dst;
234}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ereturn(context, dummy_value,...)
Definition: elog.h:277
static bool get_hex(const char *cp, char *out)
Definition: encode.c:176
int pg_mblen(const char *mbstr)
Definition: mbutils.c:1023

References ereturn, errcode(), errmsg(), get_hex(), len, and pg_mblen().

Referenced by byteain(), and hex_decode().

◆ hex_encode()

uint64 hex_encode ( const char *  src,
size_t  len,
char *  dst 
)

Definition at line 162 of file encode.c.

163{
164 const char *end = src + len;
165
166 while (src < end)
167 {
168 *dst++ = hextbl[(*src >> 4) & 0xF];
169 *dst++ = hextbl[*src & 0xF];
170 src++;
171 }
172 return (uint64) len * 2;
173}
uint64_t uint64
Definition: c.h:486
static const char hextbl[]
Definition: encode.c:148

References hextbl, and len.

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

◆ namestrcmp()

int namestrcmp ( Name  name,
const char *  str 
)

Definition at line 247 of file name.c.

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}
const char * str
#define NAMEDATALEN
const char * name

References name, NAMEDATALEN, NameStr, and str.

Referenced by AlterEventTrigger(), attnameAttNum(), CopyGetAttnums(), expanded_record_lookup_field(), GetAttributeByName(), InitPostgres(), NextCopyFromRawFields(), and SPI_fnumber().

◆ namestrcpy()

◆ network_scan_first()

Datum network_scan_first ( Datum  in)

Definition at line 1684 of file network.c.

1685{
1687}
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:641
Datum network_network(PG_FUNCTION_ARGS)
Definition: network.c:1324

References DirectFunctionCall1, and network_network().

Referenced by match_network_subset().

◆ network_scan_last()

Datum network_scan_last ( Datum  in)

Definition at line 1698 of file network.c.

1699{
1702 Int32GetDatum(-1));
1703}
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:643
Datum network_broadcast(PG_FUNCTION_ARGS)
Definition: network.c:1279
Datum inet_set_masklen(PG_FUNCTION_ARGS)
Definition: network.c:324
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212

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

Referenced by match_network_subset().

◆ numeric_float8_no_overflow()

Datum numeric_float8_no_overflow ( PG_FUNCTION_ARGS  )

Definition at line 4779 of file numeric.c.

4780{
4781 Numeric num = PG_GETARG_NUMERIC(0);
4782 double val;
4783
4784 if (NUMERIC_IS_SPECIAL(num))
4785 {
4786 if (NUMERIC_IS_PINF(num))
4787 val = HUGE_VAL;
4788 else if (NUMERIC_IS_NINF(num))
4789 val = -HUGE_VAL;
4790 else
4791 val = get_float8_nan();
4792 }
4793 else
4794 {
4795 NumericVar x;
4796
4797 init_var_from_num(num, &x);
4799 }
4800
4802}
#define NUMERIC_IS_SPECIAL(n)
Definition: numeric.c:175
static void init_var_from_num(Numeric num, NumericVar *dest)
Definition: numeric.c:7569
#define NUMERIC_IS_PINF(n)
Definition: numeric.c:207
#define NUMERIC_IS_NINF(n)
Definition: numeric.c:208
static double numericvar_to_double_no_overflow(const NumericVar *var)
Definition: numeric.c:8459
static float8 get_float8_nan(void)
Definition: float.h:123
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
long val
Definition: informix.c:689
int x
Definition: isn.c:70
#define PG_GETARG_NUMERIC(n)
Definition: numeric.h:78

References get_float8_nan(), init_var_from_num(), NUMERIC_IS_NINF, NUMERIC_IS_PINF, NUMERIC_IS_SPECIAL, numericvar_to_double_no_overflow(), PG_GETARG_NUMERIC, PG_RETURN_FLOAT8, val, and x.

Referenced by convert_numeric_to_scalar(), and gbt_numeric_penalty().

◆ oid_cmp()

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

Definition at line 258 of file oid.c.

259{
260 Oid v1 = *((const Oid *) p1);
261 Oid v2 = *((const Oid *) p2);
262
263 return pg_cmp_u32(v1, v2);
264}
static int pg_cmp_u32(uint32 a, uint32 b)
Definition: int.h:652

References p2, and pg_cmp_u32().

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

◆ oidparse()

Oid oidparse ( Node node)

Definition at line 235 of file oid.c.

236{
237 switch (nodeTag(node))
238 {
239 case T_Integer:
240 return intVal(node);
241 case T_Float:
242
243 /*
244 * Values too large for int4 will be represented as Float
245 * constants by the lexer. Accept these if they are valid OID
246 * strings.
247 */
248 return uint32in_subr(castNode(Float, node)->fval, NULL,
249 "oid", NULL);
250 default:
251 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
252 }
253 return InvalidOid; /* keep compiler quiet */
254}
#define nodeTag(nodeptr)
Definition: nodes.h:133
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
uint32 uint32in_subr(const char *s, char **endloc, const char *typname, Node *escontext)
Definition: numutils.c:898
Definition: value.h:48
#define intVal(v)
Definition: value.h:79

References castNode, elog, ERROR, intVal, InvalidOid, nodeTag, and uint32in_subr().

Referenced by get_object_address().

◆ parse_bool()

bool parse_bool ( const char *  value,
bool *  result 
)

Definition at line 31 of file bool.c.

32{
33 return parse_bool_with_len(value, strlen(value), result);
34}
bool parse_bool_with_len(const char *value, size_t len, bool *result)
Definition: bool.c:37

References parse_bool_with_len(), and value.

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

◆ parse_bool_with_len()

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

Definition at line 37 of file bool.c.

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

References len, pg_strncasecmp(), and value.

Referenced by boolin(), and parse_bool().

◆ pg_inet_cidr_ntop()

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

Definition at line 56 of file inet_cidr_ntop.c.

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}
static char * inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size)
static char * inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size)
static pg_noinline void Size size
Definition: slab.c:607
#define PGSQL_AF_INET6
Definition: inet.h:40
#define EAFNOSUPPORT
Definition: win32_port.h:376

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

Referenced by cidr_abbrev().

◆ pg_inet_net_pton()

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

Definition at line 61 of file inet_net_pton.c.

62{
63 switch (af)
64 {
65 case PGSQL_AF_INET:
66 return size == -1 ?
67 inet_net_pton_ipv4(src, dst) :
68 inet_cidr_pton_ipv4(src, dst, size);
69 case PGSQL_AF_INET6:
70 return size == -1 ?
71 inet_net_pton_ipv6(src, dst) :
72 inet_cidr_pton_ipv6(src, dst, size);
73 default:
74 errno = EAFNOSUPPORT;
75 return -1;
76 }
77}
static int inet_net_pton_ipv6(const char *src, u_char *dst)
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)
static int inet_cidr_pton_ipv4(const char *src, u_char *dst, size_t size)
Definition: inet_net_pton.c:96

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

Referenced by network_in().

◆ pg_itoa()

int pg_itoa ( int16  i,
char *  a 
)

Definition at line 1042 of file numutils.c.

1043{
1044 return pg_ltoa((int32) i, a);
1045}
int32_t int32
Definition: c.h:481
int a
Definition: isn.c:68
int pg_ltoa(int32 value, char *a)
Definition: numutils.c:1120

References a, i, and pg_ltoa().

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

◆ pg_lltoa()

int pg_lltoa ( int64  value,
char *  a 
)

Definition at line 1227 of file numutils.c.

1228{
1229 uint64 uvalue = value;
1230 int len = 0;
1231
1232 if (value < 0)
1233 {
1234 uvalue = (uint64) 0 - uvalue;
1235 a[len++] = '-';
1236 }
1237
1238 len += pg_ulltoa_n(uvalue, a + len);
1239 a[len] = '\0';
1240 return len;
1241}
int pg_ulltoa_n(uint64 value, char *a)
Definition: numutils.c:1140

References a, len, pg_ulltoa_n(), and value.

Referenced by int8out(), and printsimple().

◆ pg_ltoa()

int pg_ltoa ( int32  value,
char *  a 
)

Definition at line 1120 of file numutils.c.

1121{
1122 uint32 uvalue = (uint32) value;
1123 int len = 0;
1124
1125 if (value < 0)
1126 {
1127 uvalue = (uint32) 0 - uvalue;
1128 a[len++] = '-';
1129 }
1130 len += pg_ultoa_n(uvalue, a + len);
1131 a[len] = '\0';
1132 return len;
1133}
uint32_t uint32
Definition: c.h:485
int pg_ultoa_n(uint32 value, char *a)
Definition: numutils.c:1055

References a, len, pg_ultoa_n(), and value.

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

◆ pg_strtoint16()

int16 pg_strtoint16 ( const char *  s)

Definition at line 122 of file numutils.c.

123{
124 return pg_strtoint16_safe(s, NULL);
125}
int16 pg_strtoint16_safe(const char *s, Node *escontext)
Definition: numutils.c:128

References pg_strtoint16_safe().

◆ pg_strtoint16_safe()

int16 pg_strtoint16_safe ( const char *  s,
Node escontext 
)

Definition at line 128 of file numutils.c.

129{
130 const char *ptr = s;
131 const char *firstdigit;
132 uint16 tmp = 0;
133 bool neg = false;
134 unsigned char digit;
135 int16 result;
136
137 /*
138 * The majority of cases are likely to be base-10 digits without any
139 * underscore separator characters. We'll first try to parse the string
140 * with the assumption that's the case and only fallback on a slower
141 * implementation which handles hex, octal and binary strings and
142 * underscores if the fastpath version cannot parse the string.
143 */
144
145 /* leave it up to the slow path to look for leading spaces */
146
147 if (*ptr == '-')
148 {
149 ptr++;
150 neg = true;
151 }
152
153 /* a leading '+' is uncommon so leave that for the slow path */
154
155 /* process the first digit */
156 digit = (*ptr - '0');
157
158 /*
159 * Exploit unsigned arithmetic to save having to check both the upper and
160 * lower bounds of the digit.
161 */
162 if (likely(digit < 10))
163 {
164 ptr++;
165 tmp = digit;
166 }
167 else
168 {
169 /* we need at least one digit */
170 goto slow;
171 }
172
173 /* process remaining digits */
174 for (;;)
175 {
176 digit = (*ptr - '0');
177
178 if (digit >= 10)
179 break;
180
181 ptr++;
182
183 if (unlikely(tmp > -(PG_INT16_MIN / 10)))
184 goto out_of_range;
185
186 tmp = tmp * 10 + digit;
187 }
188
189 /* when the string does not end in a digit, let the slow path handle it */
190 if (unlikely(*ptr != '\0'))
191 goto slow;
192
193 if (neg)
194 {
195 if (unlikely(pg_neg_u16_overflow(tmp, &result)))
196 goto out_of_range;
197 return result;
198 }
199
200 if (unlikely(tmp > PG_INT16_MAX))
201 goto out_of_range;
202
203 return (int16) tmp;
204
205slow:
206 tmp = 0;
207 ptr = s;
208 /* no need to reset neg */
209
210 /* skip leading spaces */
211 while (isspace((unsigned char) *ptr))
212 ptr++;
213
214 /* handle sign */
215 if (*ptr == '-')
216 {
217 ptr++;
218 neg = true;
219 }
220 else if (*ptr == '+')
221 ptr++;
222
223 /* process digits */
224 if (ptr[0] == '0' && (ptr[1] == 'x' || ptr[1] == 'X'))
225 {
226 firstdigit = ptr += 2;
227
228 for (;;)
229 {
230 if (isxdigit((unsigned char) *ptr))
231 {
232 if (unlikely(tmp > -(PG_INT16_MIN / 16)))
233 goto out_of_range;
234
235 tmp = tmp * 16 + hexlookup[(unsigned char) *ptr++];
236 }
237 else if (*ptr == '_')
238 {
239 /* underscore must be followed by more digits */
240 ptr++;
241 if (*ptr == '\0' || !isxdigit((unsigned char) *ptr))
242 goto invalid_syntax;
243 }
244 else
245 break;
246 }
247 }
248 else if (ptr[0] == '0' && (ptr[1] == 'o' || ptr[1] == 'O'))
249 {
250 firstdigit = ptr += 2;
251
252 for (;;)
253 {
254 if (*ptr >= '0' && *ptr <= '7')
255 {
256 if (unlikely(tmp > -(PG_INT16_MIN / 8)))
257 goto out_of_range;
258
259 tmp = tmp * 8 + (*ptr++ - '0');
260 }
261 else if (*ptr == '_')
262 {
263 /* underscore must be followed by more digits */
264 ptr++;
265 if (*ptr == '\0' || *ptr < '0' || *ptr > '7')
266 goto invalid_syntax;
267 }
268 else
269 break;
270 }
271 }
272 else if (ptr[0] == '0' && (ptr[1] == 'b' || ptr[1] == 'B'))
273 {
274 firstdigit = ptr += 2;
275
276 for (;;)
277 {
278 if (*ptr >= '0' && *ptr <= '1')
279 {
280 if (unlikely(tmp > -(PG_INT16_MIN / 2)))
281 goto out_of_range;
282
283 tmp = tmp * 2 + (*ptr++ - '0');
284 }
285 else if (*ptr == '_')
286 {
287 /* underscore must be followed by more digits */
288 ptr++;
289 if (*ptr == '\0' || *ptr < '0' || *ptr > '1')
290 goto invalid_syntax;
291 }
292 else
293 break;
294 }
295 }
296 else
297 {
298 firstdigit = ptr;
299
300 for (;;)
301 {
302 if (*ptr >= '0' && *ptr <= '9')
303 {
304 if (unlikely(tmp > -(PG_INT16_MIN / 10)))
305 goto out_of_range;
306
307 tmp = tmp * 10 + (*ptr++ - '0');
308 }
309 else if (*ptr == '_')
310 {
311 /* underscore may not be first */
312 if (unlikely(ptr == firstdigit))
313 goto invalid_syntax;
314 /* and it must be followed by more digits */
315 ptr++;
316 if (*ptr == '\0' || !isdigit((unsigned char) *ptr))
317 goto invalid_syntax;
318 }
319 else
320 break;
321 }
322 }
323
324 /* require at least one digit */
325 if (unlikely(ptr == firstdigit))
326 goto invalid_syntax;
327
328 /* allow trailing whitespace, but not other trailing chars */
329 while (isspace((unsigned char) *ptr))
330 ptr++;
331
332 if (unlikely(*ptr != '\0'))
333 goto invalid_syntax;
334
335 if (neg)
336 {
337 if (unlikely(pg_neg_u16_overflow(tmp, &result)))
338 goto out_of_range;
339 return result;
340 }
341
342 if (tmp > PG_INT16_MAX)
343 goto out_of_range;
344
345 return (int16) tmp;
346
347out_of_range:
348 ereturn(escontext, 0,
349 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
350 errmsg("value \"%s\" is out of range for type %s",
351 s, "smallint")));
352
353invalid_syntax:
354 ereturn(escontext, 0,
355 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
356 errmsg("invalid input syntax for type %s: \"%s\"",
357 "smallint", s)));
358}
#define likely(x)
Definition: c.h:329
#define PG_INT16_MIN
Definition: c.h:539
uint16_t uint16
Definition: c.h:484
#define unlikely(x)
Definition: c.h:330
#define PG_INT16_MAX
Definition: c.h:540
static bool pg_neg_u16_overflow(uint16 a, int16 *result)
Definition: int.h:420
static const int8 hexlookup[128]
Definition: numutils.c:88

References ereturn, errcode(), errmsg(), hexlookup, likely, PG_INT16_MAX, PG_INT16_MIN, pg_neg_u16_overflow(), and unlikely.

Referenced by int2in(), and pg_strtoint16().

◆ pg_strtoint32()

int32 pg_strtoint32 ( const char *  s)

Definition at line 383 of file numutils.c.

384{
385 return pg_strtoint32_safe(s, NULL);
386}
int32 pg_strtoint32_safe(const char *s, Node *escontext)
Definition: numutils.c:389

References pg_strtoint32_safe().

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

◆ pg_strtoint32_safe()

int32 pg_strtoint32_safe ( const char *  s,
Node escontext 
)

Definition at line 389 of file numutils.c.

390{
391 const char *ptr = s;
392 const char *firstdigit;
393 uint32 tmp = 0;
394 bool neg = false;
395 unsigned char digit;
396 int32 result;
397
398 /*
399 * The majority of cases are likely to be base-10 digits without any
400 * underscore separator characters. We'll first try to parse the string
401 * with the assumption that's the case and only fallback on a slower
402 * implementation which handles hex, octal and binary strings and
403 * underscores if the fastpath version cannot parse the string.
404 */
405
406 /* leave it up to the slow path to look for leading spaces */
407
408 if (*ptr == '-')
409 {
410 ptr++;
411 neg = true;
412 }
413
414 /* a leading '+' is uncommon so leave that for the slow path */
415
416 /* process the first digit */
417 digit = (*ptr - '0');
418
419 /*
420 * Exploit unsigned arithmetic to save having to check both the upper and
421 * lower bounds of the digit.
422 */
423 if (likely(digit < 10))
424 {
425 ptr++;
426 tmp = digit;
427 }
428 else
429 {
430 /* we need at least one digit */
431 goto slow;
432 }
433
434 /* process remaining digits */
435 for (;;)
436 {
437 digit = (*ptr - '0');
438
439 if (digit >= 10)
440 break;
441
442 ptr++;
443
444 if (unlikely(tmp > -(PG_INT32_MIN / 10)))
445 goto out_of_range;
446
447 tmp = tmp * 10 + digit;
448 }
449
450 /* when the string does not end in a digit, let the slow path handle it */
451 if (unlikely(*ptr != '\0'))
452 goto slow;
453
454 if (neg)
455 {
456 if (unlikely(pg_neg_u32_overflow(tmp, &result)))
457 goto out_of_range;
458 return result;
459 }
460
461 if (unlikely(tmp > PG_INT32_MAX))
462 goto out_of_range;
463
464 return (int32) tmp;
465
466slow:
467 tmp = 0;
468 ptr = s;
469 /* no need to reset neg */
470
471 /* skip leading spaces */
472 while (isspace((unsigned char) *ptr))
473 ptr++;
474
475 /* handle sign */
476 if (*ptr == '-')
477 {
478 ptr++;
479 neg = true;
480 }
481 else if (*ptr == '+')
482 ptr++;
483
484 /* process digits */
485 if (ptr[0] == '0' && (ptr[1] == 'x' || ptr[1] == 'X'))
486 {
487 firstdigit = ptr += 2;
488
489 for (;;)
490 {
491 if (isxdigit((unsigned char) *ptr))
492 {
493 if (unlikely(tmp > -(PG_INT32_MIN / 16)))
494 goto out_of_range;
495
496 tmp = tmp * 16 + hexlookup[(unsigned char) *ptr++];
497 }
498 else if (*ptr == '_')
499 {
500 /* underscore must be followed by more digits */
501 ptr++;
502 if (*ptr == '\0' || !isxdigit((unsigned char) *ptr))
503 goto invalid_syntax;
504 }
505 else
506 break;
507 }
508 }
509 else if (ptr[0] == '0' && (ptr[1] == 'o' || ptr[1] == 'O'))
510 {
511 firstdigit = ptr += 2;
512
513 for (;;)
514 {
515 if (*ptr >= '0' && *ptr <= '7')
516 {
517 if (unlikely(tmp > -(PG_INT32_MIN / 8)))
518 goto out_of_range;
519
520 tmp = tmp * 8 + (*ptr++ - '0');
521 }
522 else if (*ptr == '_')
523 {
524 /* underscore must be followed by more digits */
525 ptr++;
526 if (*ptr == '\0' || *ptr < '0' || *ptr > '7')
527 goto invalid_syntax;
528 }
529 else
530 break;
531 }
532 }
533 else if (ptr[0] == '0' && (ptr[1] == 'b' || ptr[1] == 'B'))
534 {
535 firstdigit = ptr += 2;
536
537 for (;;)
538 {
539 if (*ptr >= '0' && *ptr <= '1')
540 {
541 if (unlikely(tmp > -(PG_INT32_MIN / 2)))
542 goto out_of_range;
543
544 tmp = tmp * 2 + (*ptr++ - '0');
545 }
546 else if (*ptr == '_')
547 {
548 /* underscore must be followed by more digits */
549 ptr++;
550 if (*ptr == '\0' || *ptr < '0' || *ptr > '1')
551 goto invalid_syntax;
552 }
553 else
554 break;
555 }
556 }
557 else
558 {
559 firstdigit = ptr;
560
561 for (;;)
562 {
563 if (*ptr >= '0' && *ptr <= '9')
564 {
565 if (unlikely(tmp > -(PG_INT32_MIN / 10)))
566 goto out_of_range;
567
568 tmp = tmp * 10 + (*ptr++ - '0');
569 }
570 else if (*ptr == '_')
571 {
572 /* underscore may not be first */
573 if (unlikely(ptr == firstdigit))
574 goto invalid_syntax;
575 /* and it must be followed by more digits */
576 ptr++;
577 if (*ptr == '\0' || !isdigit((unsigned char) *ptr))
578 goto invalid_syntax;
579 }
580 else
581 break;
582 }
583 }
584
585 /* require at least one digit */
586 if (unlikely(ptr == firstdigit))
587 goto invalid_syntax;
588
589 /* allow trailing whitespace, but not other trailing chars */
590 while (isspace((unsigned char) *ptr))
591 ptr++;
592
593 if (unlikely(*ptr != '\0'))
594 goto invalid_syntax;
595
596 if (neg)
597 {
598 if (unlikely(pg_neg_u32_overflow(tmp, &result)))
599 goto out_of_range;
600 return result;
601 }
602
603 if (tmp > PG_INT32_MAX)
604 goto out_of_range;
605
606 return (int32) tmp;
607
608out_of_range:
609 ereturn(escontext, 0,
610 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
611 errmsg("value \"%s\" is out of range for type %s",
612 s, "integer")));
613
614invalid_syntax:
615 ereturn(escontext, 0,
616 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
617 errmsg("invalid input syntax for type %s: \"%s\"",
618 "integer", s)));
619}
#define PG_INT32_MAX
Definition: c.h:543
#define PG_INT32_MIN
Definition: c.h:542
static bool pg_neg_u32_overflow(uint32 a, int32 *result)
Definition: int.h:493

References ereturn, errcode(), errmsg(), hexlookup, likely, PG_INT32_MAX, PG_INT32_MIN, pg_neg_u32_overflow(), and unlikely.

Referenced by int4in(), pg_strtoint32(), and process_integer_literal().

◆ pg_strtoint64()

int64 pg_strtoint64 ( const char *  s)

Definition at line 644 of file numutils.c.

645{
646 return pg_strtoint64_safe(s, NULL);
647}
int64 pg_strtoint64_safe(const char *s, Node *escontext)
Definition: numutils.c:650

References pg_strtoint64_safe().

Referenced by defGetCopyRejectLimitOption().

◆ pg_strtoint64_safe()

int64 pg_strtoint64_safe ( const char *  s,
Node escontext 
)

Definition at line 650 of file numutils.c.

651{
652 const char *ptr = s;
653 const char *firstdigit;
654 uint64 tmp = 0;
655 bool neg = false;
656 unsigned char digit;
657 int64 result;
658
659 /*
660 * The majority of cases are likely to be base-10 digits without any
661 * underscore separator characters. We'll first try to parse the string
662 * with the assumption that's the case and only fallback on a slower
663 * implementation which handles hex, octal and binary strings and
664 * underscores if the fastpath version cannot parse the string.
665 */
666
667 /* leave it up to the slow path to look for leading spaces */
668
669 if (*ptr == '-')
670 {
671 ptr++;
672 neg = true;
673 }
674
675 /* a leading '+' is uncommon so leave that for the slow path */
676
677 /* process the first digit */
678 digit = (*ptr - '0');
679
680 /*
681 * Exploit unsigned arithmetic to save having to check both the upper and
682 * lower bounds of the digit.
683 */
684 if (likely(digit < 10))
685 {
686 ptr++;
687 tmp = digit;
688 }
689 else
690 {
691 /* we need at least one digit */
692 goto slow;
693 }
694
695 /* process remaining digits */
696 for (;;)
697 {
698 digit = (*ptr - '0');
699
700 if (digit >= 10)
701 break;
702
703 ptr++;
704
705 if (unlikely(tmp > -(PG_INT64_MIN / 10)))
706 goto out_of_range;
707
708 tmp = tmp * 10 + digit;
709 }
710
711 /* when the string does not end in a digit, let the slow path handle it */
712 if (unlikely(*ptr != '\0'))
713 goto slow;
714
715 if (neg)
716 {
717 if (unlikely(pg_neg_u64_overflow(tmp, &result)))
718 goto out_of_range;
719 return result;
720 }
721
722 if (unlikely(tmp > PG_INT64_MAX))
723 goto out_of_range;
724
725 return (int64) tmp;
726
727slow:
728 tmp = 0;
729 ptr = s;
730 /* no need to reset neg */
731
732 /* skip leading spaces */
733 while (isspace((unsigned char) *ptr))
734 ptr++;
735
736 /* handle sign */
737 if (*ptr == '-')
738 {
739 ptr++;
740 neg = true;
741 }
742 else if (*ptr == '+')
743 ptr++;
744
745 /* process digits */
746 if (ptr[0] == '0' && (ptr[1] == 'x' || ptr[1] == 'X'))
747 {
748 firstdigit = ptr += 2;
749
750 for (;;)
751 {
752 if (isxdigit((unsigned char) *ptr))
753 {
754 if (unlikely(tmp > -(PG_INT64_MIN / 16)))
755 goto out_of_range;
756
757 tmp = tmp * 16 + hexlookup[(unsigned char) *ptr++];
758 }
759 else if (*ptr == '_')
760 {
761 /* underscore must be followed by more digits */
762 ptr++;
763 if (*ptr == '\0' || !isxdigit((unsigned char) *ptr))
764 goto invalid_syntax;
765 }
766 else
767 break;
768 }
769 }
770 else if (ptr[0] == '0' && (ptr[1] == 'o' || ptr[1] == 'O'))
771 {
772 firstdigit = ptr += 2;
773
774 for (;;)
775 {
776 if (*ptr >= '0' && *ptr <= '7')
777 {
778 if (unlikely(tmp > -(PG_INT64_MIN / 8)))
779 goto out_of_range;
780
781 tmp = tmp * 8 + (*ptr++ - '0');
782 }
783 else if (*ptr == '_')
784 {
785 /* underscore must be followed by more digits */
786 ptr++;
787 if (*ptr == '\0' || *ptr < '0' || *ptr > '7')
788 goto invalid_syntax;
789 }
790 else
791 break;
792 }
793 }
794 else if (ptr[0] == '0' && (ptr[1] == 'b' || ptr[1] == 'B'))
795 {
796 firstdigit = ptr += 2;
797
798 for (;;)
799 {
800 if (*ptr >= '0' && *ptr <= '1')
801 {
802 if (unlikely(tmp > -(PG_INT64_MIN / 2)))
803 goto out_of_range;
804
805 tmp = tmp * 2 + (*ptr++ - '0');
806 }
807 else if (*ptr == '_')
808 {
809 /* underscore must be followed by more digits */
810 ptr++;
811 if (*ptr == '\0' || *ptr < '0' || *ptr > '1')
812 goto invalid_syntax;
813 }
814 else
815 break;
816 }
817 }
818 else
819 {
820 firstdigit = ptr;
821
822 for (;;)
823 {
824 if (*ptr >= '0' && *ptr <= '9')
825 {
826 if (unlikely(tmp > -(PG_INT64_MIN / 10)))
827 goto out_of_range;
828
829 tmp = tmp * 10 + (*ptr++ - '0');
830 }
831 else if (*ptr == '_')
832 {
833 /* underscore may not be first */
834 if (unlikely(ptr == firstdigit))
835 goto invalid_syntax;
836 /* and it must be followed by more digits */
837 ptr++;
838 if (*ptr == '\0' || !isdigit((unsigned char) *ptr))
839 goto invalid_syntax;
840 }
841 else
842 break;
843 }
844 }
845
846 /* require at least one digit */
847 if (unlikely(ptr == firstdigit))
848 goto invalid_syntax;
849
850 /* allow trailing whitespace, but not other trailing chars */
851 while (isspace((unsigned char) *ptr))
852 ptr++;
853
854 if (unlikely(*ptr != '\0'))
855 goto invalid_syntax;
856
857 if (neg)
858 {
859 if (unlikely(pg_neg_u64_overflow(tmp, &result)))
860 goto out_of_range;
861 return result;
862 }
863
864 if (tmp > PG_INT64_MAX)
865 goto out_of_range;
866
867 return (int64) tmp;
868
869out_of_range:
870 ereturn(escontext, 0,
871 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
872 errmsg("value \"%s\" is out of range for type %s",
873 s, "bigint")));
874
875invalid_syntax:
876 ereturn(escontext, 0,
877 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
878 errmsg("invalid input syntax for type %s: \"%s\"",
879 "bigint", s)));
880}
int64_t int64
Definition: c.h:482
#define PG_INT64_MAX
Definition: c.h:546
#define PG_INT64_MIN
Definition: c.h:545
static bool pg_neg_u64_overflow(uint64 a, int64 *result)
Definition: int.h:576

References ereturn, errcode(), errmsg(), hexlookup, likely, PG_INT64_MAX, PG_INT64_MIN, pg_neg_u64_overflow(), and unlikely.

Referenced by int8in(), make_const(), and pg_strtoint64().

◆ pg_ulltoa_n()

int pg_ulltoa_n ( uint64  value,
char *  a 
)

Definition at line 1140 of file numutils.c.

1141{
1142 int olength,
1143 i = 0;
1144 uint32 value2;
1145
1146 /* Degenerate case */
1147 if (value == 0)
1148 {
1149 *a = '0';
1150 return 1;
1151 }
1152
1153 olength = decimalLength64(value);
1154
1155 /* Compute the result string. */
1156 while (value >= 100000000)
1157 {
1158 const uint64 q = value / 100000000;
1159 uint32 value3 = (uint32) (value - 100000000 * q);
1160
1161 const uint32 c = value3 % 10000;
1162 const uint32 d = value3 / 10000;
1163 const uint32 c0 = (c % 100) << 1;
1164 const uint32 c1 = (c / 100) << 1;
1165 const uint32 d0 = (d % 100) << 1;
1166 const uint32 d1 = (d / 100) << 1;
1167
1168 char *pos = a + olength - i;
1169
1170 value = q;
1171
1172 memcpy(pos - 2, DIGIT_TABLE + c0, 2);
1173 memcpy(pos - 4, DIGIT_TABLE + c1, 2);
1174 memcpy(pos - 6, DIGIT_TABLE + d0, 2);
1175 memcpy(pos - 8, DIGIT_TABLE + d1, 2);
1176 i += 8;
1177 }
1178
1179 /* Switch to 32-bit for speed */
1180 value2 = (uint32) value;
1181
1182 if (value2 >= 10000)
1183 {
1184 const uint32 c = value2 - 10000 * (value2 / 10000);
1185 const uint32 c0 = (c % 100) << 1;
1186 const uint32 c1 = (c / 100) << 1;
1187
1188 char *pos = a + olength - i;
1189
1190 value2 /= 10000;
1191
1192 memcpy(pos - 2, DIGIT_TABLE + c0, 2);
1193 memcpy(pos - 4, DIGIT_TABLE + c1, 2);
1194 i += 4;
1195 }
1196 if (value2 >= 100)
1197 {
1198 const uint32 c = (value2 % 100) << 1;
1199 char *pos = a + olength - i;
1200
1201 value2 /= 100;
1202
1203 memcpy(pos - 2, DIGIT_TABLE + c, 2);
1204 i += 2;
1205 }
1206 if (value2 >= 10)
1207 {
1208 const uint32 c = value2 << 1;
1209 char *pos = a + olength - i;
1210
1211 memcpy(pos - 2, DIGIT_TABLE + c, 2);
1212 }
1213 else
1214 *a = (char) ('0' + value2);
1215
1216 return olength;
1217}
static const char DIGIT_TABLE[200]
Definition: numutils.c:29
static int decimalLength64(const uint64 v)
Definition: numutils.c:64
char * c

References a, decimalLength64(), DIGIT_TABLE, i, and value.

Referenced by BuildQueryCompletionString(), and pg_lltoa().

◆ pg_ultoa_n()

int pg_ultoa_n ( uint32  value,
char *  a 
)

Definition at line 1055 of file numutils.c.

1056{
1057 int olength,
1058 i = 0;
1059
1060 /* Degenerate case */
1061 if (value == 0)
1062 {
1063 *a = '0';
1064 return 1;
1065 }
1066
1067 olength = decimalLength32(value);
1068
1069 /* Compute the result string. */
1070 while (value >= 10000)
1071 {
1072 const uint32 c = value - 10000 * (value / 10000);
1073 const uint32 c0 = (c % 100) << 1;
1074 const uint32 c1 = (c / 100) << 1;
1075
1076 char *pos = a + olength - i;
1077
1078 value /= 10000;
1079
1080 memcpy(pos - 2, DIGIT_TABLE + c0, 2);
1081 memcpy(pos - 4, DIGIT_TABLE + c1, 2);
1082 i += 4;
1083 }
1084 if (value >= 100)
1085 {
1086 const uint32 c = (value % 100) << 1;
1087
1088 char *pos = a + olength - i;
1089
1090 value /= 100;
1091
1092 memcpy(pos - 2, DIGIT_TABLE + c, 2);
1093 i += 2;
1094 }
1095 if (value >= 10)
1096 {
1097 const uint32 c = value << 1;
1098
1099 char *pos = a + olength - i;
1100
1101 memcpy(pos - 2, DIGIT_TABLE + c, 2);
1102 }
1103 else
1104 {
1105 *a = (char) ('0' + value);
1106 }
1107
1108 return olength;
1109}
static int decimalLength32(const uint32 v)
Definition: numutils.c:45

References a, decimalLength32(), DIGIT_TABLE, i, and value.

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

◆ pg_ultostr()

char * pg_ultostr ( char *  str,
uint32  value 
)

Definition at line 1307 of file numutils.c.

1308{
1309 int len = pg_ultoa_n(value, str);
1310
1311 return str + len;
1312}

References len, pg_ultoa_n(), str, and value.

Referenced by AppendSeconds().

◆ pg_ultostr_zeropad()

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

Definition at line 1267 of file numutils.c.

1268{
1269 int len;
1270
1271 Assert(minwidth > 0);
1272
1273 if (value < 100 && minwidth == 2) /* Short cut for common case */
1274 {
1275 memcpy(str, DIGIT_TABLE + value * 2, 2);
1276 return str + 2;
1277 }
1278
1279 len = pg_ultoa_n(value, str);
1280 if (len >= minwidth)
1281 return str + len;
1282
1283 memmove(str + minwidth - len, str, len);
1284 memset(str, '0', minwidth - len);
1285 return str + minwidth;
1286}

References Assert, DIGIT_TABLE, len, pg_ultoa_n(), str, and value.

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

◆ quote_identifier()

const char * quote_identifier ( const char *  ident)

Definition at line 12875 of file ruleutils.c.

12876{
12877 /*
12878 * Can avoid quoting if ident starts with a lowercase letter or underscore
12879 * and contains only lowercase letters, digits, and underscores, *and* is
12880 * not any SQL keyword. Otherwise, supply quotes.
12881 */
12882 int nquotes = 0;
12883 bool safe;
12884 const char *ptr;
12885 char *result;
12886 char *optr;
12887
12888 /*
12889 * would like to use <ctype.h> macros here, but they might yield unwanted
12890 * locale-specific results...
12891 */
12892 safe = ((ident[0] >= 'a' && ident[0] <= 'z') || ident[0] == '_');
12893
12894 for (ptr = ident; *ptr; ptr++)
12895 {
12896 char ch = *ptr;
12897
12898 if ((ch >= 'a' && ch <= 'z') ||
12899 (ch >= '0' && ch <= '9') ||
12900 (ch == '_'))
12901 {
12902 /* okay */
12903 }
12904 else
12905 {
12906 safe = false;
12907 if (ch == '"')
12908 nquotes++;
12909 }
12910 }
12911
12913 safe = false;
12914
12915 if (safe)
12916 {
12917 /*
12918 * Check for keyword. We quote keywords except for unreserved ones.
12919 * (In some cases we could avoid quoting a col_name or type_func_name
12920 * keyword, but it seems much harder than it's worth to tell that.)
12921 *
12922 * Note: ScanKeywordLookup() does case-insensitive comparison, but
12923 * that's fine, since we already know we have all-lower-case.
12924 */
12925 int kwnum = ScanKeywordLookup(ident, &ScanKeywords);
12926
12927 if (kwnum >= 0 && ScanKeywordCategories[kwnum] != UNRESERVED_KEYWORD)
12928 safe = false;
12929 }
12930
12931 if (safe)
12932 return ident; /* no change needed */
12933
12934 result = (char *) palloc(strlen(ident) + nquotes + 2 + 1);
12935
12936 optr = result;
12937 *optr++ = '"';
12938 for (ptr = ident; *ptr; ptr++)
12939 {
12940 char ch = *ptr;
12941
12942 if (ch == '"')
12943 *optr++ = '"';
12944 *optr++ = ch;
12945 }
12946 *optr++ = '"';
12947 *optr = '\0';
12948
12949 return result;
12950}
const uint8 ScanKeywordCategories[SCANKEYWORDS_NUM_KEYWORDS]
Definition: keywords.c:29
#define ident
Definition: indent_codes.h:47
PGDLLIMPORT const ScanKeywordList ScanKeywords
#define UNRESERVED_KEYWORD
Definition: keywords.h:20
int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords)
Definition: kwlookup.c:38
bool quote_all_identifiers
Definition: ruleutils.c:337

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

Referenced by add_cast_to(), appendFunctionName(), ATPrepAlterColumnType(), CheckMyDatabase(), copy_table(), createdb(), CreateSchemaCommand(), decompile_column_index_array(), deparseAnalyzeSql(), deparseColumnRef(), deparseOperatorName(), deparseRelation(), execute_extension_script(), ExplainIndexScanDetails(), ExplainNode(), ExplainTargetRel(), flatten_set_variable_args(), format_operator_extended(), generate_operator_clause(), generate_operator_name(), get_column_alias_list(), get_from_clause_coldeflist(), get_from_clause_item(), get_insert_query_def(), get_json_table(), get_json_table_columns(), get_json_table_nested_columns(), get_merge_query_def(), get_opclass_name(), get_parameter(), get_reloptions(), get_rte_alias(), get_rule_expr(), get_rule_windowclause(), get_rule_windowspec(), get_select_query_def(), get_target_list(), get_update_query_targetlist_def(), get_utility_query_def(), get_variable(), get_windowfunc_expr_helper(), get_with_clause(), get_xmltable(), getObjectIdentityParts(), libpqrcv_alter_slot(), make_ruledef(), NameListToQuotedString(), old_9_6_invalidate_hash_indexes(), pg_get_constraintdef_worker(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), pg_get_statisticsobj_worker(), pg_get_triggerdef_worker(), pg_identify_object(), PLy_quote_ident(), postgresExplainForeignScan(), postgresImportForeignSchema(), print_function_arguments(), process_extension_updates(), processIndirection(), quote_ident(), quote_object_name(), quote_qualified_identifier(), regnamespaceout(), regoperout(), regroleout(), ReplicationSlotDropAtPubNode(), 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(), tuple_to_stringinfo(), and worker_spi_main().

◆ quote_literal_cstr()

char * quote_literal_cstr ( const char *  rawstr)

Definition at line 103 of file quote.c.

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

References len, palloc(), and quote_literal_internal().

Referenced by build_tuplestore_recursively(), fetch_remote_table_info(), get_sql_delete(), get_sql_insert(), get_sql_update(), get_tuple_of_interest(), GetPublicationsStr(), pg_decode_commit_prepared_txn(), pg_decode_prepare_txn(), pg_decode_rollback_prepared_txn(), pg_decode_stream_prepare(), PLy_quote_literal(), PLy_quote_nullable(), text_format_string_conversion(), and validate_remote_info().

◆ quote_qualified_identifier()

◆ regexp_fixed_prefix()

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

Definition at line 1953 of file regexp.c.

1955{
1956 char *result;
1957 regex_t *re;
1958 int cflags;
1959 int re_result;
1960 pg_wchar *str;
1961 size_t slen;
1962 size_t maxlen;
1963 char errMsg[100];
1964
1965 *exact = false; /* default result */
1966
1967 /* Compile RE */
1968 cflags = REG_ADVANCED;
1969 if (case_insensitive)
1970 cflags |= REG_ICASE;
1971
1972 re = RE_compile_and_cache(text_re, cflags | REG_NOSUB, collation);
1973
1974 /* Examine it to see if there's a fixed prefix */
1975 re_result = pg_regprefix(re, &str, &slen);
1976
1977 switch (re_result)
1978 {
1979 case REG_NOMATCH:
1980 return NULL;
1981
1982 case REG_PREFIX:
1983 /* continue with wchar conversion */
1984 break;
1985
1986 case REG_EXACT:
1987 *exact = true;
1988 /* continue with wchar conversion */
1989 break;
1990
1991 default:
1992 /* re failed??? */
1993 pg_regerror(re_result, re, errMsg, sizeof(errMsg));
1994 ereport(ERROR,
1995 (errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
1996 errmsg("regular expression failed: %s", errMsg)));
1997 break;
1998 }
1999
2000 /* Convert pg_wchar result back to database encoding */
2001 maxlen = pg_database_encoding_max_length() * slen + 1;
2002 result = (char *) palloc(maxlen);
2003 slen = pg_wchar2mb_with_len(str, result, slen);
2004 Assert(slen < maxlen);
2005
2006 pfree(str);
2007
2008 return result;
2009}
#define ereport(elevel,...)
Definition: elog.h:149
unsigned int pg_wchar
Definition: mbprint.c:31
int pg_wchar2mb_with_len(const pg_wchar *from, char *to, int len)
Definition: mbutils.c:1008
int pg_database_encoding_max_length(void)
Definition: mbutils.c:1546
void pfree(void *pointer)
Definition: mcxt.c:1521
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
Definition: regerror.c:60
#define REG_ICASE
Definition: regex.h:184
#define REG_NOMATCH
Definition: regex.h:216
#define REG_EXACT
Definition: regex.h:240
#define REG_PREFIX
Definition: regex.h:239
#define REG_ADVANCED
Definition: regex.h:181
#define REG_NOSUB
Definition: regex.h:185
#define regex_t
Definition: regex.h:245
regex_t * RE_compile_and_cache(text *text_re, int cflags, Oid collation)
Definition: regexp.c:141
int pg_regprefix(regex_t *re, chr **string, size_t *slength)
Definition: regprefix.c:46

References Assert, ereport, errcode(), errmsg(), ERROR, palloc(), pfree(), 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_NOSUB, REG_PREFIX, regex_t, and str.

Referenced by regex_fixed_prefix().

◆ text_to_cstring()

char * text_to_cstring ( const text t)

Definition at line 217 of file varlena.c.

218{
219 /* must cast away the const, unfortunately */
220 text *tunpacked = pg_detoast_datum_packed(unconstify(text *, t));
221 int len = VARSIZE_ANY_EXHDR(tunpacked);
222 char *result;
223
224 result = (char *) palloc(len + 1);
225 memcpy(result, VARDATA_ANY(tunpacked), len);
226 result[len] = '\0';
227
228 if (tunpacked != t)
229 pfree(tunpacked);
230
231 return result;
232}
#define unconstify(underlying_type, expr)
Definition: c.h:1199
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
Definition: fmgr.c:1864
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317

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

Referenced by array_to_text(), array_to_text_null(), binary_upgrade_add_sub_rel_state(), binary_upgrade_create_empty_extension(), binary_upgrade_replorigin_advance(), 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_schema_name(), convert_server_name(), convert_tablespace_name(), convert_type_name(), crosstab(), crosstab_hash(), cursor_to_xml(), cursor_to_xmlschema(), daitch_mokotoff(), database_to_xml(), database_to_xml_and_xmlschema(), database_to_xmlschema(), datetime_to_char_body(), dblink_cancel_query(), dblink_close(), dblink_connect(), dblink_disconnect(), dblink_error_message(), dblink_exec(), dblink_fetch(), dblink_get_notify(), dblink_is_busy(), dblink_open(), dblink_record_internal(), dblink_send_query(), deserialize_deflist(), difference(), dmetaphone(), dmetaphone_alt(), do_to_timestamp(), ExecAlterExtensionStmt(), execute_extension_script(), executeDateTimeMethod(), get_raw_page_fork(), get_raw_page_fork_1_9(), has_param_priv_byname(), has_sequence_privilege_id_name(), has_sequence_privilege_name(), has_sequence_privilege_name_name(), injection_points_attach(), injection_points_cached(), injection_points_detach(), injection_points_load(), injection_points_run(), injection_points_stats_numcalls(), injection_points_wakeup(), json_object_field(), json_object_field_text(), jsonb_set_lax(), JsonItemFromDatum(), ltree_addtext(), ltree_textadd(), NUM_cache(), parse_datetime(), parse_ident(), pg_backup_start(), pg_create_restore_point(), pg_crypt(), pg_current_logfile(), pg_get_expr_worker(), pg_get_logical_snapshot_info(), pg_get_logical_snapshot_meta(), pg_get_serial_sequence(), pg_index_column_has_property(), pg_index_has_property(), pg_indexam_has_property(), pg_input_is_valid_common(), pg_logical_emit_message_bytea(), pg_ls_replslotdir(), 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_split_walfile_name(), pg_stat_get_progress_info(), pg_stat_get_replication_slot(), pg_stat_have_stats(), pg_stat_reset_replication_slot(), pg_stat_reset_shared(), pg_stat_reset_slru(), pgxml_texttoxmlchar(), phraseto_tsquery_byid(), plainto_tsquery_byid(), postgres_fdw_disconnect(), query_to_xml(), query_to_xml_and_xmlschema(), query_to_xmlschema(), quote_ident(), quote_ident_cstr(), range_constructor3(), regress_setenv(), 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_canonicalize_path(), test_predtest(), test_slru_page_write(), text2ltree(), text_concat_ws(), textToQualifiedNameList(), to_date(), to_regclass(), to_regcollation(), to_regnamespace(), to_regoper(), to_regoperator(), to_regproc(), to_regprocedure(), to_regrole(), to_regtype(), to_regtypemod(), to_tsquery_byid(), ts_stat_sql(), tsquery_rewrite_query(), tuple_data_split(), unicode_is_normalized(), unicode_normalize_func(), verify_heapam(), websearch_to_tsquery_byid(), X509_NAME_field_to_text(), xml_out_internal(), xmlconcat(), xmlpi(), xmlroot(), and xpath_table().

◆ text_to_cstring_buffer()

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

Definition at line 248 of file varlena.c.

249{
250 /* must cast away the const, unfortunately */
251 text *srcunpacked = pg_detoast_datum_packed(unconstify(text *, src));
252 size_t src_len = VARSIZE_ANY_EXHDR(srcunpacked);
253
254 if (dst_len > 0)
255 {
256 dst_len--;
257 if (dst_len >= src_len)
258 dst_len = src_len;
259 else /* ensure truncation is encoding-safe */
260 dst_len = pg_mbcliplen(VARDATA_ANY(srcunpacked), src_len, dst_len);
261 memcpy(dst, VARDATA_ANY(srcunpacked), dst_len);
262 dst[dst_len] = '\0';
263 }
264
265 if (srcunpacked != src)
266 pfree(srcunpacked);
267}
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition: mbutils.c:1083

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

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

◆ type_maximum_size()

int32 type_maximum_size ( Oid  type_oid,
int32  typemod 
)

Definition at line 412 of file format_type.c.

413{
414 if (typemod < 0)
415 return -1;
416
417 switch (type_oid)
418 {
419 case BPCHAROID:
420 case VARCHAROID:
421 /* typemod includes varlena header */
422
423 /* typemod is in characters not bytes */
424 return (typemod - VARHDRSZ) *
426 + VARHDRSZ;
427
428 case NUMERICOID:
429 return numeric_maximum_size(typemod);
430
431 case VARBITOID:
432 case BITOID:
433 /* typemod is the (max) number of bits */
434 return (typemod + (BITS_PER_BYTE - 1)) / BITS_PER_BYTE
435 + 2 * sizeof(int32);
436 }
437
438 /* Unknown type, or unlimited-width type such as 'text' */
439 return -1;
440}
int32 numeric_maximum_size(int32 typmod)
Definition: numeric.c:953
int GetDatabaseEncoding(void)
Definition: mbutils.c:1261
#define BITS_PER_BYTE
int pg_encoding_max_length(int encoding)
Definition: wchar.c:2127

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

Referenced by get_typavgwidth(), and heapam_relation_needs_toast_table().

◆ uint32in_subr()

uint32 uint32in_subr ( const char *  s,
char **  endloc,
const char *  typname,
Node escontext 
)

Definition at line 898 of file numutils.c.

900{
901 uint32 result;
902 unsigned long cvt;
903 char *endptr;
904
905 errno = 0;
906 cvt = strtoul(s, &endptr, 0);
907
908 /*
909 * strtoul() normally only sets ERANGE. On some systems it may also set
910 * EINVAL, which simply means it couldn't parse the input string. Be sure
911 * to report that the same way as the standard error indication (that
912 * endptr == s).
913 */
914 if ((errno && errno != ERANGE) || endptr == s)
915 ereturn(escontext, 0,
916 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
917 errmsg("invalid input syntax for type %s: \"%s\"",
918 typname, s)));
919
920 if (errno == ERANGE)
921 ereturn(escontext, 0,
922 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
923 errmsg("value \"%s\" is out of range for type %s",
924 s, typname)));
925
926 if (endloc)
927 {
928 /* caller wants to deal with rest of string */
929 *endloc = endptr;
930 }
931 else
932 {
933 /* allow only whitespace after number */
934 while (*endptr && isspace((unsigned char) *endptr))
935 endptr++;
936 if (*endptr)
937 ereturn(escontext, 0,
938 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
939 errmsg("invalid input syntax for type %s: \"%s\"",
940 typname, s)));
941 }
942
943 result = (uint32) cvt;
944
945 /*
946 * Cope with possibility that unsigned long is wider than uint32, in which
947 * case strtoul will not raise an error for some values that are out of
948 * the range of uint32.
949 *
950 * For backwards compatibility, we want to accept inputs that are given
951 * with a minus sign, so allow the input value if it matches after either
952 * signed or unsigned extension to long.
953 *
954 * To ensure consistent results on 32-bit and 64-bit platforms, make sure
955 * the error message is the same as if strtoul() had returned ERANGE.
956 */
957#if PG_UINT32_MAX != ULONG_MAX
958 if (cvt != (unsigned long) result &&
959 cvt != (unsigned long) ((int) result))
960 ereturn(escontext, 0,
961 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
962 errmsg("value \"%s\" is out of range for type %s",
963 s, typname)));
964#endif
965
966 return result;
967}

References ereturn, errcode(), errmsg(), and typname.

Referenced by cidin(), oidin(), oidparse(), oidvectorin(), and xidin().

◆ uint64in_subr()

uint64 uint64in_subr ( const char *  s,
char **  endloc,
const char *  typname,
Node escontext 
)

Definition at line 985 of file numutils.c.

987{
988 uint64 result;
989 char *endptr;
990
991 errno = 0;
992 result = strtou64(s, &endptr, 0);
993
994 /*
995 * strtoul[l] normally only sets ERANGE. On some systems it may also set
996 * EINVAL, which simply means it couldn't parse the input string. Be sure
997 * to report that the same way as the standard error indication (that
998 * endptr == s).
999 */
1000 if ((errno && errno != ERANGE) || endptr == s)
1001 ereturn(escontext, 0,
1002 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1003 errmsg("invalid input syntax for type %s: \"%s\"",
1004 typname, s)));
1005
1006 if (errno == ERANGE)
1007 ereturn(escontext, 0,
1008 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1009 errmsg("value \"%s\" is out of range for type %s",
1010 s, typname)));
1011
1012 if (endloc)
1013 {
1014 /* caller wants to deal with rest of string */
1015 *endloc = endptr;
1016 }
1017 else
1018 {
1019 /* allow only whitespace after number */
1020 while (*endptr && isspace((unsigned char) *endptr))
1021 endptr++;
1022 if (*endptr)
1023 ereturn(escontext, 0,
1024 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1025 errmsg("invalid input syntax for type %s: \"%s\"",
1026 typname, s)));
1027 }
1028
1029 return result;
1030}

References ereturn, errcode(), errmsg(), and typname.

Referenced by xid8in().

◆ xidComparator()

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

Definition at line 152 of file xid.c.

153{
154 TransactionId xid1 = *(const TransactionId *) arg1;
155 TransactionId xid2 = *(const TransactionId *) arg2;
156
157 return pg_cmp_u32(xid1, xid2);
158}
uint32 TransactionId
Definition: c.h:606

References pg_cmp_u32().

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

◆ xidLogicalComparator()

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

Definition at line 169 of file xid.c.

170{
171 TransactionId xid1 = *(const TransactionId *) arg1;
172 TransactionId xid2 = *(const TransactionId *) arg2;
173
176
177 if (TransactionIdPrecedes(xid1, xid2))
178 return -1;
179
180 if (TransactionIdPrecedes(xid2, xid1))
181 return 1;
182
183 return 0;
184}
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280
#define TransactionIdIsNormal(xid)
Definition: transam.h:42

References Assert, TransactionIdIsNormal, and TransactionIdPrecedes().

Referenced by ProcArrayApplyRecoveryInfo().

Variable Documentation

◆ quote_all_identifiers

PGDLLIMPORT bool quote_all_identifiers
extern

Definition at line 337 of file ruleutils.c.

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