Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb9fa80

Browse files
committed
Add new OID alias type regnamespace
Catalog version bumpedKyotaro HORIGUCHI
1 parent0c90f67 commitcb9fa80

File tree

13 files changed

+174
-4
lines changed

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"> showsan 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+
<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+
caseREGNAMESPACEOID:
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
returnoidsend(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+
Oidresult=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+
Oidresult;
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+
Oidnspid=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+
returnoidrecv(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+
returnoidsend(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
caseREGCONFIGOID:
36213621
caseREGDICTIONARYOID:
36223622
caseREGROLEOID:
3623+
caseREGNAMESPACEOID:
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
caseREGCONFIGOID:
37273728
caseREGDICTIONARYOID:
37283729
caseREGROLEOID:
3730+
caseREGNAMESPACEOID:
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
caseREGCONFIGOID:
152152
caseREGDICTIONARYOID:
153153
caseREGROLEOID:
154+
caseREGNAMESPACEOID:
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-
#defineCATALOG_VERSION_NO201505083
56+
#defineCATALOG_VERSION_NO201505091
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 (2340960ib ));
218218
DATA(insert (4096201288af ));
219219
DATA(insert (4096230ab ));
220+
DATA(insert (2640890ib ));
221+
DATA(insert (4089260ib ));
222+
DATA(insert (2040891287if ));
223+
DATA(insert (214089313if ));
224+
DATA(insert (2340890ib ));
225+
DATA(insert (4089201288af ));
226+
DATA(insert (4089230ab ));
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_regrolePGNSP 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 ( regnamespaceinPGNSP 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 ( regnamespaceoutPGNSP 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_regnamespacePGNSP 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_validatorPGNSP 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 PGUID4 t b N f t \054 0 0 4097 re
568568
DESCR("registered role");
569569
#defineREGROLEOID4096
570570

571+
DATA(insertOID=4089 (regnamespacePGNSPPGUID4tbNft \054004090regnamespaceinregnamespaceoutregnamespacerecvregnamespacesend---ipf0-100_null__null__null_ ));
572+
DESCR("registered namespace");
573+
#defineREGNAMESPACEOID4089
574+
571575
DATA(insertOID=2207 (_regprocedurePGNSPPGUID-1fbAft \054022020array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
572576
DATA(insertOID=2208 (_regoperPGNSPPGUID-1fbAft \054022030array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
573577
DATA(insertOID=2209 (_regoperatorPGNSPPGUID-1fbAft \054022040array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
574578
DATA(insertOID=2210 (_regclassPGNSPPGUID-1fbAft \054022050array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
575579
DATA(insertOID=2211 (_regtypePGNSPPGUID-1fbAft \054022060array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
576580
#defineREGTYPEARRAYOID 2211
577581
DATA(insertOID=4097 (_regrolePGNSPPGUID-1fbAft \054040960array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
582+
DATA(insertOID=4090 (_regnamespacePGNSPPGUID-1fbAft \054040890array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
578583

579584
/* uuid */
580585
DATA(insertOID=2950 (uuidPGNSPPGUID16fbUft \054002951uuid_inuuid_outuuid_recvuuid_send---cpf0-100_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
externDatumregrolerecv(PG_FUNCTION_ARGS);
636636
externDatumregrolesend(PG_FUNCTION_ARGS);
637637
externDatumto_regrole(PG_FUNCTION_ARGS);
638+
externDatumregnamespacein(PG_FUNCTION_ARGS);
639+
externDatumregnamespaceout(PG_FUNCTION_ARGS);
640+
externDatumregnamespacerecv(PG_FUNCTION_ARGS);
641+
externDatumregnamespacesend(PG_FUNCTION_ARGS);
642+
externDatumto_regnamespace(PG_FUNCTION_ARGS);
638643
externDatumregconfigin(PG_FUNCTION_ARGS);
639644
externDatumregconfigout(PG_FUNCTION_ARGS);
640645
externDatumregconfigrecv(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)

[8]ページ先頭

©2009-2025 Movatter.jp