8000 Add new OID alias type regnamespace · postgres/postgres@cb9fa80 · GitHub
[go: up one dir, main page]

Skip to content

Commit cb9fa80

Browse files
committed
Add new OID alias type regnamespace
Catalog version bumped Kyotaro HORIGUCHI
1 parent 0c90f67 commit cb9fa80

File tree

13 files changed

+174
-4
lines changed
  • utils
  • test/regress
  • 13 files changed

    +174
    -4
    lines changed

    doc/src/sgml/datatype.sgml

    Lines changed: 10 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4321,9 +4321,9 @@ SET xmloption TO { DOCUMENT | CONTENT };
    43214321
    an object identifier. There are also several alias types for
    43224322
    <type>oid</>: <type>regproc</>, <type>regprocedure</>,
    43234323
    <type>regoper</>, <type>regoperator</>, <type>regclass</>,
    4324-
    <type>regtype</>, <type>regrole</>, <type>regconfig</>, and
    4325-
    <type>regdictionary</>. <xref linkend="datatype-oid-table"> shows
    4326-
    an overview.
    4324+
    <type>regtype</>, <type>regrole</>, <type>regnamespace</>,
    4325+
    <type>regconfig</>, and <type>regdictionary</>.
    4326+
    <xref linkend="datatype-oid-table"> shows an overview.
    43274327
    </para>
    43284328

    43294329
    <para>
    @@ -4438,6 +4438,13 @@ SELECT * FROM pg_attribute
    44384438
    <entry><literal>smithee</></entry>
    44394439
    </row>
    44404440

    4441+
    <row>
    4442+
    <entry><type>regnamespace</></entry>
    4443+
    <entry><structname>pg_namespace</></entry>
    4444+
    <entry>namespace name</entry>
    4445< 67E6 /code>+
    <entry><literal>pg_catalog</></entry>
    4446+
    </row>
    4447+
    44414448
    <row>
    44424449
    <entry><type>regconfig</></entry>
    44434450
    <entry><structname>pg_ts_config</></entry>

    src/backend/bootstrap/bootstrap.c

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -115,6 +115,8 @@ static const struct typinfo TypInfo[] = {
    115115
    F_REGTYPEIN, F_REGTYPEOUT},
    116116
    {"regrole", REGROLEOID, 0, 4, true, 'i', 'p', InvalidOid,
    117117
    F_REGROLEIN, F_REGROLEOUT},
    118+
    {"regnamespace", REGNAMESPACEOID, 0, 4, true, 'i', 'p', InvalidOid,
    119+
    F_REGNAMESPACEIN, F_REGNAMESPACEOUT},
    118120
    {"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
    119121
    F_TEXTIN, F_TEXTOUT},
    120122
    {"oid", OIDOID, 0, 4, true, 'i', 'p', InvalidOid,

    src/backend/catalog/dependency.c

    Lines changed: 8 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1603,6 +1603,14 @@ find_expr_references_walker(Node *node,
    16031603
    context->addrs);
    16041604
    break;
    16051605

    1606+
    case REGNAMESPACEOID:
    1607+
    objoid = DatumGetObjectId(con->constvalue);
    1608+
    if (SearchSysCacheExists1(NAMESPACEOID,
    1609+
    ObjectIdGetDatum(objoid)))
    1610+
    add_object_address(OCLASS_SCHEMA, objoid, 0,
    1611+
    context->addrs);
    1612+
    break;
    1613+
    16061614
    /*
    16071615
    * Dependencies for regrole should be shared among all
    16081616
    * databases, so explicitly inhibit to have dependencies.

    src/backend/utils/adt/regproc.c

    Lines changed: 96 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1656,7 +1656,103 @@ regrolesend(PG_FUNCTION_ARGS)
    16561656
    return oidsend(fcinfo);
    16571657
    }
    16581658

    1659+
    /*
    1660+
    * regnamespacein - converts "nspname" to namespace OID
    1661+
    *
    1662+
    * We also accept a numeric OID, for symmetry with the output routine.
    1663+
    *
    1664+
    * '-' signifies unknown (OID 0). In all other cases, the input must
    1665+
    * match an existing pg_namespace entry.
    1666+
    */
    1667+
    Datum
    1668+
    regnamespacein(PG_FUNCTION_ARGS)
    1669+
    {
    1670+
    char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
    1671+
    Oid result = InvalidOid;
    1672+
    1673+
    /* '-' ? */
    1674+
    if (strcmp(nsp_name_or_oid, "-") == 0)
    1675+
    PG_RETURN_OID(InvalidOid);
    1676+
    1677+
    /* Numeric OID? */
    1678+
    if (nsp_name_or_oid[0] >= '0' &&
    1679+
    nsp_name_or_oid[0] <= '9' &&
    1680+
    strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
    1681+
    {
    1682+
    result = DatumGetObjectId(DirectFunctionCall1(oidin,
    1683+
    CStringGetDatum(nsp_name_or_oid)));
    1684+
    PG_RETURN_OID(result);
    1685+
    }
    1686+
    1687+
    /* Normal case: see if the name matches any pg_namespace entry. */
    1688+
    result = get_namespace_oid(nsp_name_or_oid, false);
    1689+
    1690+
    PG_RETURN_OID(result);
    1691+
    }
    1692+
    1693+
    /*
    1694+
    * to_regnamespace - converts "nspname" to namespace OID
    1695+
    *
    1696+
    * If the name is not found, we return NULL.
    1697+
    */
    1698+
    Datum
    1699+
    to_regnamespace(PG_FUNCTION_ARGS)
    1700+
    {
    1701+
    char *nsp_name = PG_GETARG_CSTRING(0);
    1702+
    Oid result;
    1703+
    1704+
    result = get_namespace_oid(nsp_name, true);
    1705+
    1706+
    if (OidIsValid(result))
    1707+
    PG_RETURN_OID(result);
    1708+
    else
    1709+
    PG_RETURN_NULL();
    1710+
    }
    1711+
    1712+
    /*
    1713+
    * regnamespaceout - converts namespace OID to "nsp_name"
    1714+
    */
    1715+
    Datum
    1716+
    regnamespaceout(PG_FUNCTION_ARGS)
    1717+
    {
    1718+
    Oid nspid = PG_GETARG_OID(0);
    1719+
    char *result;
    1720+
    1721+
    if (nspid == InvalidOid)
    1722+
    {
    1723+
    result = pstrdup("-");
    1724+
    PG_RETURN_CSTRING(result);
    1725+
    }
    16591726

    1727+
    result = get_namespace_name(nspid);
    1728+
    if (!result)
    1729+
    {
    1730+
    /* If OID doesn't match any namespace, return it numerically */
    1731+
    result = (char *) palloc(NAMEDATALEN);
    1732+
    snprintf(result, NAMEDATALEN, "%u", nspid);
    1733+
    }
    1734+
    PG_RETURN_CSTRING(result);
    1735+
    }
    1736+
    1737+
    /*
    1738+
    * regnamespacerecv - converts external binary format to regnamespace
    1739+
    */
    1740+
    Datum
    1741+
    regnamespacerecv(PG_FUNCTION_ARGS)
    1742+
    {
    1743+
    /* Exactly the same as oidrecv, so share code */
    1744+
    return oidrecv(fcinfo);
    1745+
    }
    1746+
    1747+
    /*
    1748+
    * regnamespacesend - converts regnamespace to binary format
    1749+
    */
    1750+
    Datum
    1751+
    regnamespacesend(PG_FUNCTION_ARGS)
    1752+
    {
    1753+
    /* Exactly the same as oidsend, so share code */
    1754+
    return oidsend(fcinfo);
    1755+
    }
    16601756

    16611757
    /*
    16621758
    * text_regclass: convert text to regclass

    src/backend/utils/adt/selfuncs.c

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -3620,6 +3620,7 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue,
    36203620
    case REGCONFIGOID:
    36213621
    case REGDICTIONARYOID:
    36223622
    case REGROLEOID:
    3623+
    case REGNAMESPACEOID:
    36233624
    *scaledvalue = convert_numeric_to_scalar(value, valuetypid);
    36243625
    *scaledlobound = convert_numeric_to_scalar(lobound, boundstypid);
    36253626
    *scaledhibound = convert_numeric_to_scalar(hibound, boundstypid);
    @@ -3726,6 +3727,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
    37263727
    case REGCONFIGOID:
    37273728
    case REGDICTIONARYOID:
    37283729
    case REGROLEOID:
    3730+
    case REGNAMESPACEOID:
    37293731
    /* we can treat OIDs as integers... */
    37303732
    return (double) DatumGetObjectId(value);
    37313733
    }

    src/backend/utils/cache/catcache.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -151,6 +151,7 @@ GetCCHashEqFuncs(Oid keytype, PGFunction *hashfunc, RegProcedure *eqfunc)
    151151
    case REGCONFIGOID:
    152152
    case REGDICTIONARYOID:
    153153
    case REGROLEOID:
    154+
    case REGNAMESPACEOID:
    154155
    *hashfunc = hashoid;
    155156

    156157
    *eqfunc = F_OIDEQ;

    src/include/catalog/catversion.h

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -53,6 +53,6 @@
    5353
    */
    5454

    5555
    /* yyyymmddN */
    56-
    #define CATALOG_VERSION_NO 201505083
    56+
    #define CATALOG_VERSION_NO 201505091
    5757

    5858
    #endif

    src/include/catalog/pg_cast.h

    Lines changed: 7 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -217,6 +217,13 @@ DATA(insert ( 21 4096 313 i f ));
    217217
    DATA(insert ( 23 4096 0 i b ));
    218218
    DATA(insert ( 4096 20 1288 a f ));
    219219
    DATA(insert ( 4096 23 0 a b ));
    220+
    DATA(insert ( 26 4089 0 i b ));
    221+
    DATA(insert ( 4089 26 0 i b ));
    222+
    DATA(insert ( 20 4089 1287 i f ));
    223+
    DATA(insert ( 21 4089 313 i f ));
    224+
    DATA(insert ( 23 4089 0 i b ));
    225+
    DATA(insert ( 4089 20 1288 a f ));
    226+
    DATA(insert ( 4089 23 0 a b ));
    220227

    221228
    /*
    222229
    * String category

    src/include/catalog/pg_proc.h

    Lines changed: 11 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -3488,6 +3488,13 @@ DESCR("I/O");
    34883488
    DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
    34893489
    DESCR("convert role name to regrole");
    34903490

    3491+
    DATA(insert OID = 4084 ( regnamespacein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ _null_ regnamespacein _null_ _null_ _null_ ));
    3492+
    DESCR("I/O");
    3493+
    DATA(insert OID = 4085 ( regnamespaceout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4089" _null_ _null_ _null_ _null_ _null_ regnamespaceout _null_ _null_ _null_ ));
    3494+
    DESCR("I/O");
    3495+
    DATA(insert OID = 4086 ( to_regnamespace PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ _null_ to_regnamespace _null_ _null_ _null_ ));
    3496+
    DESCR("convert namespace name to regnamespace");
    3497+
    34913498
    DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));
    34923499
    DESCR("(internal)");
    34933500
    DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ ));
    @@ -3888,6 +3895,10 @@ DATA(insert OID = 4094 ( regrolerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i
    38883895
    DESCR("I/O");
    38893896
    DATA(insert OID = 4095 ( regrolesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4096" _null_ _null_ _null_ _null_ _null_ regrolesend _null_ _null_ _null_ ));
    38903897
    DESCR("I/O");
    3898+
    DATA(insert OID = 4087 ( regnamespacerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4089 "2281" _null_ _null_ _null_ _null_ _null_ regnamespacerecv _null_ _null_ _null_ ));
    3899+
    DESCR("I/O");
    3900+
    DATA(insert OID = 4088 ( regnamespacesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4089" _null_ _null_ _null_ _null_ _null_ regnamespacesend _null_ _null_ _null_ ));
    3901+
    DESCR("I/O");
    38913902
    DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ ));
    38923903
    DESCR("I/O");
    38933904
    DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ ));

    src/include/catalog/pg_type.h

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -568,13 +568,18 @@ DATA(insert OID = 4096 ( regrole PGNSP PGUID 4 t b N f t \054 0 0 4097 re
    568568
    DESCR("registered role");
    569569
    #define REGROLEOID 4096
    570570

    571+
    DATA(insert OID = 4089 ( regnamespace PGNSP PGUID 4 t b N f t \054 0 0 4090 regnamespacein regnamespaceout regnamespacerecv regnamespacesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
    572+
    DESCR("registered namespace");
    573+
    #define REGNAMESPACEOID 4089
    574+
    571575
    DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
    572576
    DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
    573577
    DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
    574578
    DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
    575579
    DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
    576580
    #define REGTYPEARRAYOID 2211
    577581
    DATA(insert OID = 4097 ( _regrole PGNSP PGUID -1 f b A f t \054 0 4096 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
    582+
    DATA(insert OID = 4090 ( _regnamespace PGNSP PGUID -1 f b A f t \054 0 4089 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
    578583

    579584
    /* uuid */
    580585
    DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ ));

    src/include/utils/builtins.h

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -635,6 +635,11 @@ extern Datum regroleout(PG_FUNCTION_ARGS);
    635635
    extern Datum regrolerecv(PG_FUNCTION_ARGS);
    636636
    extern Datum regrolesend(PG_FUNCTION_ARGS);
    637637
    extern Datum to_regrole(PG_FUNCTION_ARGS);
    638+
    extern Datum regnamespacein(PG_FUNCTION_ARGS);
    639+
    extern Datum regnamespaceout(PG_FUNCTION_ARGS);
    640+
    extern Datum regnamespacerecv(PG_FUNCTION_ARGS);
    641+
    extern Datum regnamespacesend(PG_FUNCTION_ARGS);
    642+
    extern Datum to_regnamespace(PG_FUNCTION_ARGS);
    638643
    extern Datum regconfigin(PG_FUNCTION_ARGS);
    639644
    extern Datum regconfigout(PG_FUNCTION_ARGS);
    640645
    extern Datum regconfigrecv(PG_FUNCTION_ARGS);

    src/test/regress/expected/regproc.out

    Lines changed: 22 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -46,6 +46,12 @@ SELECT regrole('regtestrole');
    4646
    regtestrole
    4747
    (1 row)
    4848

    49+
    SELECT regnamespace('pg_catalog');
    50+
    regnamespace
    51+
    --------------
    52+
    pg_catalog
    53+
    (1 row)
    54+
    4955
    SELECT to_regoper('||/');
    5056
    to_regoper
    5157
    ------------
    @@ -88,6 +94,12 @@ SELECT to_regrole('regtestrole');
    8894
    regtestrole
    8995
    (1 row)
    9096

    97+
    SELECT to_regnamespace('pg_catalog');
    98+
    to_regnamespace
    99+
    -----------------
    100+
    pg_catalog
    101+
    (1 row)
    102+
    91103
    -- with schemaname
    92104
    SELECT regoper('pg_catalog.||/');
    93105
    regoper
    @@ -186,6 +198,10 @@ SELECT regrole('regtestrole');
    186198
    ERROR: role "regtestrole" does not exist
    187199
    LINE 1: SELECT regrole('regtestrole');
    188200
    ^
    201+
    SELECT regnamespace('nonexistent');
    202+
    ERROR: schema "nonexistent" does not exist
    203+
    LINE 1: SELECT regnamespace('nonexistent');
    204+
    ^
    189205
    -- with schemaname
    190206
    SELECT regoper('ng_catalog.||/');
    191207
    ERROR: schema "ng_catalog" does not exist
    @@ -255,6 +271,12 @@ SELECT to_regrole('regtestrole');
    255271

    256272
    (1 row)
    257273

    274+
    SELECT to_regnamespace('nonexistent');
    275+
    to_regnamespace
    276+
    -----------------
    277+
    278+
    (1 row)
    279+
    258280
    -- with schemaname
    259281
    SELECT to_regoper('ng_catalog.||/');
    260282
    to_regoper

    src/test/regress/sql/regproc.sql

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -14,6 +14,7 @@ SELECT regprocedure('abs(numeric)');
    1414
    SELECT regclass('pg_class');
    1515
    SELECT regtype('int4');
    1616
    SELECT regrole('regtestrole');
    17+
    SELECT regnamespace('pg_catalog');
    1718

    1819
    SELECT to_regoper('||/');
    1920
    SELECT to_regoperator('+(int4,int4)');
    @@ -22,6 +23,7 @@ SELECT to_regprocedure('abs(numeric)');
    2223
    SELECT to_regclass('pg_class');
    2324
    SELECT to_regtype('int4');
    2425
    SELECT to_regrole('regtestrole');
    26+
    SELECT to_regnamespace('pg_catalog');
    2527

    2628
    -- with schemaname
    2729

    @@ -51,6 +53,7 @@ SELECT regprocedure('absinthe(numeric)');
    5153
    SELECT regclass('pg_classes');
    5254
    SELECT regtype('int3');
    5355
    SELECT regrole('regtestrole');
    56+
    SELECT regnamespace('nonexistent');
    5457

    5558
    -- with schemaname
    5659

    @@ -72,6 +75,7 @@ SELECT to_regprocedure('absinthe(numeric)');
    7275
    SELECT to_regclass('pg_classes');
    7376
    SELECT to_regtype('int3');
    7477
    SELECT to_regrole('regtestrole');
    78+
    SELECT to_regnamespace('nonexistent');
    7579

    7680
    -- with schemaname
    7781

    0 commit comments

    Comments
     (0)
    0