PostgreSQL Source Code git master
Loading...
Searching...
No Matches
name.c File Reference
#include "postgres.h"
#include "catalog/namespace.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/varlena.h"
Include dependency graph for name.c:

Go to the source code of this file.

Functions

Datum namein (PG_FUNCTION_ARGS)
 
Datum nameout (PG_FUNCTION_ARGS)
 
Datum namerecv (PG_FUNCTION_ARGS)
 
Datum namesend (PG_FUNCTION_ARGS)
 
static int namecmp (Name arg1, Name arg2, Oid collid)
 
Datum nameeq (PG_FUNCTION_ARGS)
 
Datum namene (PG_FUNCTION_ARGS)
 
Datum namelt (PG_FUNCTION_ARGS)
 
Datum namele (PG_FUNCTION_ARGS)
 
Datum namegt (PG_FUNCTION_ARGS)
 
Datum namege (PG_FUNCTION_ARGS)
 
Datum btnamecmp (PG_FUNCTION_ARGS)
 
Datum btnamesortsupport (PG_FUNCTION_ARGS)
 
void namestrcpy (Name name, const char *str)
 
int namestrcmp (Name name, const char *str)
 
Datum current_user (PG_FUNCTION_ARGS)
 
Datum session_user (PG_FUNCTION_ARGS)
 
Datum current_schema (PG_FUNCTION_ARGS)
 
Datum current_schemas (PG_FUNCTION_ARGS)
 
Datum nameconcatoid (PG_FUNCTION_ARGS)
 

Function Documentation

◆ btnamecmp()

Datum btnamecmp ( PG_FUNCTION_ARGS  )

Definition at line 202 of file name.c.

203{
206
208}
#define PG_GETARG_NAME(n)
Definition fmgr.h:279
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_GET_COLLATION()
Definition fmgr.h:198
static int namecmp(Name arg1, Name arg2, Oid collid)
Definition name.c:135
static int fb(int x)
Definition c.h:760

References fb(), namecmp(), PG_GET_COLLATION, PG_GETARG_NAME, and PG_RETURN_INT32.

◆ btnamesortsupport()

Datum btnamesortsupport ( PG_FUNCTION_ARGS  )

Definition at line 211 of file name.c.

212{
214 Oid collid = ssup->ssup_collation;
215 MemoryContext oldcontext;
216
217 oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
218
219 /* Use generic string SortSupport */
221
222 MemoryContextSwitchTo(oldcontext);
223
225}
Oid collid
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
unsigned int Oid
struct SortSupportData * SortSupport
Definition sortsupport.h:58
MemoryContext ssup_cxt
Definition sortsupport.h:66
void varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
Definition varlena.c:1624

References collid, fb(), MemoryContextSwitchTo(), PG_GETARG_POINTER, PG_RETURN_VOID, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, and varstr_sortsupport().

◆ current_schema()

Datum current_schema ( PG_FUNCTION_ARGS  )

Definition at line 279 of file name.c.

280{
281 List *search_path = fetch_search_path(false);
282 char *nspname;
283
284 if (search_path == NIL)
286 nspname = get_namespace_name(linitial_oid(search_path));
287 list_free(search_path);
288 if (!nspname)
289 PG_RETURN_NULL(); /* recently-deleted namespace? */
291}
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
void list_free(List *list)
Definition list.c:1546
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3516
Datum namein(PG_FUNCTION_ARGS)
Definition name.c:48
List * fetch_search_path(bool includeImplicit)
Definition namespace.c:4889
#define NIL
Definition pg_list.h:68
#define linitial_oid(l)
Definition pg_list.h:180
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
Definition pg_list.h:54

References CStringGetDatum(), DirectFunctionCall1, fetch_search_path(), get_namespace_name(), linitial_oid, list_free(), namein(), NIL, PG_RETURN_DATUM, and PG_RETURN_NULL.

Referenced by ExecEvalSQLValueFunction().

◆ current_schemas()

Datum current_schemas ( PG_FUNCTION_ARGS  )

Definition at line 294 of file name.c.

295{
296 List *search_path = fetch_search_path(PG_GETARG_BOOL(0));
297 ListCell *l;
298 Datum *names;
299 int i;
300 ArrayType *array;
301
302 names = (Datum *) palloc(list_length(search_path) * sizeof(Datum));
303 i = 0;
304 foreach(l, search_path)
305 {
306 char *nspname;
307
308 nspname = get_namespace_name(lfirst_oid(l));
309 if (nspname) /* watch out for deleted namespace */
310 {
311 names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname));
312 i++;
313 }
314 }
315 list_free(search_path);
316
317 array = construct_array_builtin(names, i, NAMEOID);
318
319 PG_RETURN_POINTER(array);
320}
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
int i
Definition isn.c:77
void * palloc(Size size)
Definition mcxt.c:1387
static int list_length(const List *l)
Definition pg_list.h:152
#define lfirst_oid(lc)
Definition pg_list.h:174
uint64_t Datum
Definition postgres.h:70

References construct_array_builtin(), CStringGetDatum(), DirectFunctionCall1, fb(), fetch_search_path(), get_namespace_name(), i, lfirst_oid, list_free(), list_length(), namein(), palloc(), PG_GETARG_BOOL, and PG_RETURN_POINTER.

◆ current_user()

Datum current_user ( PG_FUNCTION_ARGS  )

Definition at line 263 of file name.c.

264{
266}
Oid GetUserId(void)
Definition miscinit.c:469
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition miscinit.c:988

References CStringGetDatum(), DirectFunctionCall1, GetUserId(), GetUserNameFromId(), namein(), and PG_RETURN_DATUM.

Referenced by ExecEvalSQLValueFunction().

◆ namecmp()

static int namecmp ( Name  arg1,
Name  arg2,
Oid  collid 
)
static

Definition at line 135 of file name.c.

136{
137 /* Fast path for common case used in system catalogs */
138 if (collid == C_COLLATION_OID)
140
141 /* Else rely on the varstr infrastructure */
144 collid);
145}
#define NameStr(name)
Definition c.h:765
#define NAMEDATALEN
int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
Definition varlena.c:1308

References collid, fb(), NAMEDATALEN, NameStr, and varstr_cmp().

Referenced by btnamecmp(), nameeq(), namege(), namegt(), namele(), namelt(), and namene().

◆ nameconcatoid()

Datum nameconcatoid ( PG_FUNCTION_ARGS  )

Definition at line 333 of file name.c.

334{
336 Oid oid = PG_GETARG_OID(1);
337 Name result;
338 char suffix[20];
339 int suflen;
340 int namlen;
341
342 suflen = snprintf(suffix, sizeof(suffix), "_%u", oid);
344
345 /* Truncate oversize input by truncating name part, not suffix */
346 if (namlen + suflen >= NAMEDATALEN)
348
349 /* We use palloc0 here to ensure result is zero-padded */
350 result = (Name) palloc0(NAMEDATALEN);
351 memcpy(NameStr(*result), NameStr(*nam), namlen);
352 memcpy(NameStr(*result) + namlen, suffix, suflen);
353
354 PG_RETURN_NAME(result);
355}
NameData * Name
Definition c.h:763
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_RETURN_NAME(x)
Definition fmgr.h:365
int pg_mbcliplen(const char *mbstr, int len, int limit)
Definition mbutils.c:1086
void * palloc0(Size size)
Definition mcxt.c:1417
#define snprintf
Definition port.h:260

References fb(), NAMEDATALEN, NameStr, palloc0(), PG_GETARG_NAME, PG_GETARG_OID, pg_mbcliplen(), PG_RETURN_NAME, and snprintf.

◆ nameeq()

Datum nameeq ( PG_FUNCTION_ARGS  )

Definition at line 148 of file name.c.

149{
152
154}
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360

References fb(), namecmp(), PG_GET_COLLATION, PG_GETARG_NAME, and PG_RETURN_BOOL.

◆ namege()

Datum namege ( PG_FUNCTION_ARGS  )

Definition at line 193 of file name.c.

194{
197
199}

References fb(), namecmp(), PG_GET_COLLATION, PG_GETARG_NAME, and PG_RETURN_BOOL.

◆ namegt()

Datum namegt ( PG_FUNCTION_ARGS  )

Definition at line 184 of file name.c.

185{
188
190}

References fb(), namecmp(), PG_GET_COLLATION, PG_GETARG_NAME, and PG_RETURN_BOOL.

◆ namein()

◆ namele()

Datum namele ( PG_FUNCTION_ARGS  )

Definition at line 175 of file name.c.

176{
179
181}

References fb(), namecmp(), PG_GET_COLLATION, PG_GETARG_NAME, and PG_RETURN_BOOL.

◆ namelt()

Datum namelt ( PG_FUNCTION_ARGS  )

Definition at line 166 of file name.c.

167{
170
172}

References fb(), namecmp(), PG_GET_COLLATION, PG_GETARG_NAME, and PG_RETURN_BOOL.

◆ namene()

Datum namene ( PG_FUNCTION_ARGS  )

Definition at line 157 of file name.c.

158{
161
163}

References fb(), namecmp(), PG_GET_COLLATION, PG_GETARG_NAME, and PG_RETURN_BOOL.

◆ nameout()

Datum nameout ( PG_FUNCTION_ARGS  )

Definition at line 71 of file name.c.

72{
73 Name s = PG_GETARG_NAME(0);
74
76}
#define PG_RETURN_CSTRING(x)
Definition fmgr.h:364
char * pstrdup(const char *in)
Definition mcxt.c:1781

References NameStr, PG_GETARG_NAME, PG_RETURN_CSTRING, and pstrdup().

Referenced by make_greater_string(), and RelationBuildTriggers().

◆ namerecv()

Datum namerecv ( PG_FUNCTION_ARGS  )

Definition at line 82 of file name.c.

83{
85 Name result;
86 char *str;
87 int nbytes;
88
89 str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
90 if (nbytes >= NAMEDATALEN)
93 errmsg("identifier too long"),
94 errdetail("Identifier must be less than %d characters.",
95 NAMEDATALEN)));
96 result = (NameData *) palloc0(NAMEDATALEN);
97 memcpy(result, str, nbytes);
98 pfree(str);
99 PG_RETURN_NAME(result);
100}
int errdetail(const char *fmt,...)
Definition elog.c:1216
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
const char * str
void pfree(void *pointer)
Definition mcxt.c:1616
static char buf[DEFAULT_XLOG_SEG_SIZE]
char * pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes)
Definition pqformat.c:545
struct StringInfoData * StringInfo
Definition string.h:15

References buf, ereport, errcode(), errdetail(), errmsg(), ERROR, fb(), NAMEDATALEN, palloc0(), pfree(), PG_GETARG_POINTER, PG_RETURN_NAME, pq_getmsgtext(), and str.

◆ namesend()

Datum namesend ( PG_FUNCTION_ARGS  )

Definition at line 106 of file name.c.

107{
108 Name s = PG_GETARG_NAME(0);
110
112 pq_sendtext(&buf, NameStr(*s), strlen(NameStr(*s)));
114}
#define PG_RETURN_BYTEA_P(x)
Definition fmgr.h:373
void pq_sendtext(StringInfo buf, const char *str, int slen)
Definition pqformat.c:172
void pq_begintypsend(StringInfo buf)
Definition pqformat.c:325
bytea * pq_endtypsend(StringInfo buf)
Definition pqformat.c:345

References buf, fb(), NameStr, PG_GETARG_NAME, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendtext().

◆ 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 * name

References fb(), name, NAMEDATALEN, NameStr, and str.

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

◆ namestrcpy()

◆ session_user()