1/*-------------------------------------------------------------------------
4 * Functions for the built-in type "name".
6 * name replaces char16 and is carefully implemented so that it
7 * is a string of physical length NAMEDATALEN.
8 * DO NOT use hard-coded constants anywhere
9 * always use NAMEDATALEN as the symbolic constant! - jolly 8/21/95
12 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
13 * Portions Copyright (c) 1994, Regents of the University of California
17 * src/backend/utils/adt/name.c
19 *-------------------------------------------------------------------------
35/*****************************************************************************
36 * USER I/O ROUTINES (none) *
37 *****************************************************************************/
41 * namein - converts cstring to internal representation
44 * [Old] Currently if strlen(s) < NAMEDATALEN, the extra chars are nulls
45 * Now, always NULL terminated
56 /* Truncate oversize input */
60 /* We use palloc0 here to ensure result is zero-padded */
68 * nameout - converts internal representation to cstring
79 * namerecv - converts external binary format to name
92 (
errcode(ERRCODE_NAME_TOO_LONG),
93 errmsg(
"identifier too long"),
94 errdetail(
"Identifier must be less than %d characters.",
97 memcpy(result,
str, nbytes);
103 * namesend - converts name to binary format
117/*****************************************************************************
118 * COMPARISON/SORTING ROUTINES *
119 *****************************************************************************/
122 * nameeq - returns 1 iff arguments are equal
123 * namene - returns 1 iff arguments are not equal
124 * namelt - returns 1 iff a < b
125 * namele - returns 1 iff a <= b
126 * namegt - returns 1 iff a > b
127 * namege - returns 1 iff a >= b
129 * Note that the use of strncmp with NAMEDATALEN limit is mostly historical;
130 * strcmp would do as well, because we do not allow NAME values that don't
131 * have a '0円' terminator. Whatever might be past the terminator is not
132 * considered relevant to comparisons.
137 /* Fast path for common case used in system catalogs */
138 if (
collid == C_COLLATION_OID)
141 /* Else rely on the varstr infrastructure */
219 /* Use generic string SortSupport */
228/*****************************************************************************
229 * MISCELLANEOUS PUBLIC ROUTINES *
230 *****************************************************************************/
235 /* NB: We need to zero-pad the destination. */
241 * Compare a NAME to a C string
243 * Assumes C collation always; be careful when using this for
244 * anything but equality checks!
252 return -1;
/* NULL < anything */
254 return 1;
/* NULL < anything */
260 * SQL-functions CURRENT_USER, SESSION_USER
276 * SQL-functions CURRENT_SCHEMA, CURRENT_SCHEMAS
284 if (search_path ==
NIL)
304 foreach(l, search_path)
309 if (nspname)
/* watch out for deleted namespace */
323 * SQL-function nameconcatoid(name, oid) returns name
325 * This is used in the information_schema to produce specific_name columns,
326 * which are supposed to be unique per schema. We achieve that (in an ugly
327 * way) by appending the object's OID. The result is the same as
328 * (1ドル::text || '_' || 2ドル::text)::name
329 * except that, if it would not fit in NAMEDATALEN, we make it do so by
330 * truncating the name input (not the oid).
342 suflen =
snprintf(suffix,
sizeof(suffix),
"_%u", oid);
343 namlen = strlen(
NameStr(*nam));
345 /* Truncate oversize input by truncating name part, not suffix */
349 /* We use palloc0 here to ensure result is zero-padded */
352 memcpy(
NameStr(*result) + namlen, suffix, suflen);
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_NAME(n)
#define PG_RETURN_INT32(x)
#define PG_RETURN_NAME(x)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_GET_COLLATION()
#define PG_RETURN_BOOL(x)
void list_free(List *list)
char * get_namespace_name(Oid nspid)
int pg_mbcliplen(const char *mbstr, int len, int limit)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
Oid GetSessionUserId(void)
char * GetUserNameFromId(Oid roleid, bool noerr)
Datum nameout(PG_FUNCTION_ARGS)
Datum nameeq(PG_FUNCTION_ARGS)
Datum nameconcatoid(PG_FUNCTION_ARGS)
Datum btnamecmp(PG_FUNCTION_ARGS)
Datum current_user(PG_FUNCTION_ARGS)
Datum btnamesortsupport(PG_FUNCTION_ARGS)
int namestrcmp(Name name, const char *str)
Datum namele(PG_FUNCTION_ARGS)
Datum namerecv(PG_FUNCTION_ARGS)
Datum namegt(PG_FUNCTION_ARGS)
void namestrcpy(Name name, const char *str)
Datum session_user(PG_FUNCTION_ARGS)
Datum namelt(PG_FUNCTION_ARGS)
Datum namein(PG_FUNCTION_ARGS)
Datum current_schema(PG_FUNCTION_ARGS)
Datum namege(PG_FUNCTION_ARGS)
static int namecmp(Name arg1, Name arg2, Oid collid)
Datum namesend(PG_FUNCTION_ARGS)
Datum current_schemas(PG_FUNCTION_ARGS)
Datum namene(PG_FUNCTION_ARGS)
List * fetch_search_path(bool includeImplicit)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static int list_length(const List *l)
static Datum CStringGetDatum(const char *X)
struct SortSupportData * SortSupport
struct StringInfoData * StringInfo
int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
void varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)