Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

name.c File Reference

#include "postgres.h"
#include "catalog/namespace.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 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)
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)
int namecpy (Name n1, Name n2)
int 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)

Function Documentation

Datum current_schema ( PG_FUNCTION_ARGS   ) 

Definition at line 280 of file name.c.

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

{
    List       *search_path = fetch_search_path(false);
    char       *nspname;

    if (search_path == NIL)
        PG_RETURN_NULL();
    nspname = get_namespace_name(linitial_oid(search_path));
    list_free(search_path);
    if (!nspname)
        PG_RETURN_NULL();       /* recently-deleted namespace? */
    PG_RETURN_DATUM(DirectFunctionCall1(namein, CStringGetDatum(nspname)));
}

Datum current_schemas ( PG_FUNCTION_ARGS   ) 

Definition at line 295 of file name.c.

References construct_array(), CStringGetDatum, DirectFunctionCall1, fetch_search_path(), get_namespace_name(), lfirst_oid, list_free(), list_length(), namein(), NAMEOID, palloc(), PG_GETARG_BOOL, and PG_RETURN_POINTER.

{
    List       *search_path = fetch_search_path(PG_GETARG_BOOL(0));
    ListCell   *l;
    Datum      *names;
    int         i;
    ArrayType  *array;

    names = (Datum *) palloc(list_length(search_path) * sizeof(Datum));
    i = 0;
    foreach(l, search_path)
    {
        char       *nspname;

        nspname = get_namespace_name(lfirst_oid(l));
        if (nspname)            /* watch out for deleted namespace */
        {
            names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname));
            i++;
        }
    }
    list_free(search_path);

    array = construct_array(names, i,
                            NAMEOID,
                            NAMEDATALEN,        /* sizeof(Name) */
                            false,      /* Name is not by-val */
                            'c');       /* alignment of Name */

    PG_RETURN_POINTER(array);
}

Datum current_user ( PG_FUNCTION_ARGS   ) 
int namecpy ( Name  n1,
Name  n2 
)

Definition at line 191 of file name.c.

References NAMEDATALEN, and NameStr.

{
    if (!n1 || !n2)
        return -1;
    strncpy(NameStr(*n1), NameStr(*n2), NAMEDATALEN);
    return 0;
}

Datum nameeq ( PG_FUNCTION_ARGS   ) 

Definition at line 134 of file name.c.

References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.

{
    Name        arg1 = PG_GETARG_NAME(0);
    Name        arg2 = PG_GETARG_NAME(1);

    PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) == 0);
}

Datum namege ( PG_FUNCTION_ARGS   ) 

Definition at line 179 of file name.c.

References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.

{
    Name        arg1 = PG_GETARG_NAME(0);
    Name        arg2 = PG_GETARG_NAME(1);

    PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) >= 0);
}

Datum namegt ( PG_FUNCTION_ARGS   ) 

Definition at line 170 of file name.c.

References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.

{
    Name        arg1 = PG_GETARG_NAME(0);
    Name        arg2 = PG_GETARG_NAME(1);

    PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) > 0);
}

Datum namein ( PG_FUNCTION_ARGS   ) 
Datum namele ( PG_FUNCTION_ARGS   ) 

Definition at line 161 of file name.c.

References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.

{
    Name        arg1 = PG_GETARG_NAME(0);
    Name        arg2 = PG_GETARG_NAME(1);

    PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) <= 0);
}

Datum namelt ( PG_FUNCTION_ARGS   ) 

Definition at line 152 of file name.c.

References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.

{
    Name        arg1 = PG_GETARG_NAME(0);
    Name        arg2 = PG_GETARG_NAME(1);

    PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) < 0);
}

Datum namene ( PG_FUNCTION_ARGS   ) 

Definition at line 143 of file name.c.

References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_BOOL.

{
    Name        arg1 = PG_GETARG_NAME(0);
    Name        arg2 = PG_GETARG_NAME(1);

    PG_RETURN_BOOL(strncmp(NameStr(*arg1), NameStr(*arg2), NAMEDATALEN) != 0);
}

Datum nameout ( PG_FUNCTION_ARGS   ) 
Datum namerecv ( PG_FUNCTION_ARGS   ) 

Definition at line 80 of file name.c.

References buf, StringInfoData::cursor, ereport, errcode(), errdetail(), errmsg(), ERROR, StringInfoData::len, NAMEDATALEN, palloc0(), pfree(), PG_GETARG_POINTER, PG_RETURN_NAME, and pq_getmsgtext().

{
    StringInfo  buf = (StringInfo) PG_GETARG_POINTER(0);
    Name        result;
    char       *str;
    int         nbytes;

    str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
    if (nbytes >= NAMEDATALEN)
        ereport(ERROR,
                (errcode(ERRCODE_NAME_TOO_LONG),
                 errmsg("identifier too long"),
                 errdetail("Identifier must be less than %d characters.",
                           NAMEDATALEN)));
    result = (NameData *) palloc0(NAMEDATALEN);
    memcpy(result, str, nbytes);
    pfree(str);
    PG_RETURN_NAME(result);
}

Datum namesend ( PG_FUNCTION_ARGS   ) 
int namestrcmp ( Name  name,
const char *  str 
)

Definition at line 248 of file name.c.

References NameStr.

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

{
    if (!name && !str)
        return 0;
    if (!name)
        return -1;              /* NULL < anything */
    if (!str)
        return 1;               /* NULL < anything */
    return strncmp(NameStr(*name), str, NAMEDATALEN);
}

int namestrcpy ( Name  name,
const char *  str 
)
Datum session_user ( PG_FUNCTION_ARGS   )