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

Commita2b1faa

Browse files
committed
Implement type regcollation
This will be helpful for a following commit and it's also justgenerally useful, like the other reg* types.Author: Julien RouhaudReviewed-by: Thomas Munro and Michael PaquierDiscussion:https://postgr.es/m/CAEepm%3D0uEQCpfq_%2BLYFBdArCe4Ot98t1aR4eYiYTe%3DyavQygiQ%40mail.gmail.com
1 parentc31132d commita2b1faa

File tree

11 files changed

+256
-3
lines changed

11 files changed

+256
-3
lines changed

‎doc/src/sgml/datatype.sgml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,6 +4476,10 @@ INSERT INTO mytable VALUES(-1); -- fails
44764476
<primary>regclass</primary>
44774477
</indexterm>
44784478

4479+
<indexterm zone="datatype-oid">
4480+
<primary>regcollation</primary>
4481+
</indexterm>
4482+
44794483
<indexterm zone="datatype-oid">
44804484
<primary>regconfig</primary>
44814485
</indexterm>
@@ -4602,6 +4606,12 @@ SELECT * FROM pg_attribute
46024606
<entry><literal>pg_type</literal></entry>
46034607
</row>
46044608

4609+
<row>
4610+
<entry><type>regcollation</type></entry>
4611+
<entry><structname>pg_collation</structname></entry>
4612+
<entry>collation name</entry>
4613+
<entry><literal>"POSIX"</literal></entry>
4614+
</row>
46054615

46064616
<row>
46074617
<entry><type>regconfig</type></entry>

‎doc/src/sgml/func.sgml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18177,6 +18177,10 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
1817718177
<primary>to_regclass</primary>
1817818178
</indexterm>
1817918179

18180+
<indexterm>
18181+
<primary>to_regcollation</primary>
18182+
</indexterm>
18183+
1818018184
<indexterm>
1818118185
<primary>to_regnamespace</primary>
1818218186
</indexterm>
@@ -18389,6 +18393,11 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
1838918393
<entry><type>regclass</type></entry>
1839018394
<entry>get the OID of the named relation</entry>
1839118395
</row>
18396+
<row>
18397+
<entry><literal><function>to_regcollation(<parameter>coll_name</parameter>)</function></literal></entry>
18398+
<entry><type>regcollation</type></entry>
18399+
<entry>get the OID of the named collation</entry>
18400+
</row>
1839218401
<row>
1839318402
<entry><literal><function>to_regnamespace(<parameter>schema_name</parameter>)</function></literal></entry>
1839418403
<entry><type>regnamespace</type></entry>
@@ -18720,11 +18729,11 @@ SELECT collation for ('foo' COLLATE "de_DE");
1872018729
</para>
1872118730

1872218731
<para>
18723-
The functions <function>to_regclass</function>,
18732+
The functions <function>to_regclass</function>, <function>to_regcollation</function>,
1872418733
<function>to_regnamespace</function>, <function>to_regoper</function>,
1872518734
<function>to_regoperator</function>, <function>to_regrole</function>,
1872618735
<function>to_regproc</function>, <function>to_regprocedure</function>, and
18727-
<function>to_regtype</function>, functions translate relation, schema,
18736+
<function>to_regtype</function>, functions translate relation,collation,schema,
1872818737
operator, role, function, and type names (given as <type>text</type>) to
1872918738
objects of the corresponding <type>reg*</type> type (see <xref
1873018739
linkend="datatype-oid"/> about the types). These functions differ from a

‎doc/src/sgml/ref/pgupgrade.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ psql --username=postgres --file=script.sql postgres
774774
<application>pg_upgrade</application> does not support upgrading of databases
775775
containing table columns using these <type>reg*</type> OID-referencing system data types:
776776
<simplelist>
777+
<member><type>regcollation</type></member>
777778
<member><type>regconfig</type></member>
778779
<member><type>regdictionary</type></member>
779780
<member><type>regnamespace</type></member>

‎src/backend/utils/adt/regproc.c

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include"access/htup_details.h"
2525
#include"catalog/namespace.h"
2626
#include"catalog/pg_class.h"
27+
#include"catalog/pg_collation.h"
2728
#include"catalog/pg_operator.h"
2829
#include"catalog/pg_proc.h"
2930
#include"catalog/pg_ts_config.h"
@@ -1043,6 +1044,157 @@ regclasssend(PG_FUNCTION_ARGS)
10431044
}
10441045

10451046

1047+
/*
1048+
* regcollationin- converts "collationname" to collation OID
1049+
*
1050+
* We also accept a numeric OID, for symmetry with the output routine.
1051+
*
1052+
* '-' signifies unknown (OID 0). In all other cases, the input must
1053+
* match an existing pg_collation entry.
1054+
*/
1055+
Datum
1056+
regcollationin(PG_FUNCTION_ARGS)
1057+
{
1058+
char*collation_name_or_oid=PG_GETARG_CSTRING(0);
1059+
Oidresult=InvalidOid;
1060+
List*names;
1061+
1062+
/* '-' ? */
1063+
if (strcmp(collation_name_or_oid,"-")==0)
1064+
PG_RETURN_OID(InvalidOid);
1065+
1066+
/* Numeric OID? */
1067+
if (collation_name_or_oid[0] >='0'&&
1068+
collation_name_or_oid[0] <='9'&&
1069+
strspn(collation_name_or_oid,"0123456789")==strlen(collation_name_or_oid))
1070+
{
1071+
result=DatumGetObjectId(DirectFunctionCall1(oidin,
1072+
CStringGetDatum(collation_name_or_oid)));
1073+
PG_RETURN_OID(result);
1074+
}
1075+
1076+
/* Else it's a name, possibly schema-qualified */
1077+
1078+
/* The rest of this wouldn't work in bootstrap mode */
1079+
if (IsBootstrapProcessingMode())
1080+
elog(ERROR,"regcollation values must be OIDs in bootstrap mode");
1081+
1082+
/*
1083+
* Normal case: parse the name into components and see if it matches any
1084+
* pg_collation entries in the current search path.
1085+
*/
1086+
names=stringToQualifiedNameList(collation_name_or_oid);
1087+
1088+
result=get_collation_oid(names, false);
1089+
1090+
PG_RETURN_OID(result);
1091+
}
1092+
1093+
/*
1094+
* to_regcollation- converts "collationname" to collation OID
1095+
*
1096+
* If the name is not found, we return NULL.
1097+
*/
1098+
Datum
1099+
to_regcollation(PG_FUNCTION_ARGS)
1100+
{
1101+
char*collation_name=text_to_cstring(PG_GETARG_TEXT_PP(0));
1102+
Oidresult;
1103+
List*names;
1104+
1105+
/*
1106+
* Parse the name into components and see if it matches any pg_collation
1107+
* entries in the current search path.
1108+
*/
1109+
names=stringToQualifiedNameList(collation_name);
1110+
1111+
/* We might not even have permissions on this relation; don't lock it. */
1112+
result=get_collation_oid(names, true);
1113+
1114+
if (OidIsValid(result))
1115+
PG_RETURN_OID(result);
1116+
else
1117+
PG_RETURN_NULL();
1118+
}
1119+
1120+
/*
1121+
* regcollationout- converts collation OID to "collation_name"
1122+
*/
1123+
Datum
1124+
regcollationout(PG_FUNCTION_ARGS)
1125+
{
1126+
Oidcollationid=PG_GETARG_OID(0);
1127+
char*result;
1128+
HeapTuplecollationtup;
1129+
1130+
if (collationid==InvalidOid)
1131+
{
1132+
result=pstrdup("-");
1133+
PG_RETURN_CSTRING(result);
1134+
}
1135+
1136+
collationtup=SearchSysCache1(COLLOID,ObjectIdGetDatum(collationid));
1137+
1138+
if (HeapTupleIsValid(collationtup))
1139+
{
1140+
Form_pg_collationcollationform= (Form_pg_collation)GETSTRUCT(collationtup);
1141+
char*collationname=NameStr(collationform->collname);
1142+
1143+
/*
1144+
* In bootstrap mode, skip the fancy namespace stuff and just return
1145+
* the collation name. (This path is only needed for debugging output
1146+
* anyway.)
1147+
*/
1148+
if (IsBootstrapProcessingMode())
1149+
result=pstrdup(collationname);
1150+
else
1151+
{
1152+
char*nspname;
1153+
1154+
/*
1155+
* Would this collation be found by regcollationin? If not, qualify it.
1156+
*/
1157+
if (CollationIsVisible(collationid))
1158+
nspname=NULL;
1159+
else
1160+
nspname=get_namespace_name(collationform->collnamespace);
1161+
1162+
result=quote_qualified_identifier(nspname,collationname);
1163+
}
1164+
1165+
ReleaseSysCache(collationtup);
1166+
}
1167+
else
1168+
{
1169+
/* If OID doesn't match any pg_collation entry, return it numerically */
1170+
result= (char*)palloc(NAMEDATALEN);
1171+
snprintf(result,NAMEDATALEN,"%u",collationid);
1172+
}
1173+
1174+
PG_RETURN_CSTRING(result);
1175+
}
1176+
1177+
/*
1178+
*regcollationrecv- converts external binary format to regcollation
1179+
*/
1180+
Datum
1181+
regcollationrecv(PG_FUNCTION_ARGS)
1182+
{
1183+
/* Exactly the same as oidrecv, so share code */
1184+
returnoidrecv(fcinfo);
1185+
}
1186+
1187+
/*
1188+
*regcollationsend- converts regcollation to binary format
1189+
*/
1190+
Datum
1191+
regcollationsend(PG_FUNCTION_ARGS)
1192+
{
1193+
/* Exactly the same as oidsend, so share code */
1194+
returnoidsend(fcinfo);
1195+
}
1196+
1197+
10461198
/*
10471199
* regtypein- converts "typename" to type OID
10481200
*

‎src/bin/pg_upgrade/check.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
10281028
" WHERE nspname = 'pg_catalog') AND"
10291029
"t.typname IN ( "
10301030
/* regclass.oid is preserved, so 'regclass' is OK */
1031+
" 'regcollation', "
10311032
" 'regconfig', "
10321033
" 'regdictionary', "
10331034
" 'regnamespace', "

‎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_NO202003051
56+
#defineCATALOG_VERSION_NO202003181
5757

5858
#endif

‎src/include/catalog/pg_cast.dat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@
189189
castcontext => 'a', castmethod => 'f' },
190190
{ castsource => 'regclass', casttarget => 'int4', castfunc => '0',
191191
castcontext => 'a', castmethod => 'b' },
192+
{ castsource => 'oid', casttarget => 'regcollation', castfunc => '0',
193+
castcontext => 'i', castmethod => 'b' },
194+
{ castsource => 'regcollation', casttarget => 'oid', castfunc => '0',
195+
castcontext => 'i', castmethod => 'b' },
196+
{ castsource => 'int8', casttarget => 'regcollation', castfunc => 'oid',
197+
castcontext => 'i', castmethod => 'f' },
198+
{ castsource => 'int2', casttarget => 'regcollation', castfunc => 'int4(int2)',
199+
castcontext => 'i', castmethod => 'f' },
200+
{ castsource => 'int4', casttarget => 'regcollation', castfunc => '0',
201+
castcontext => 'i', castmethod => 'b' },
202+
{ castsource => 'regcollation', casttarget => 'int8', castfunc => 'int8(oid)',
203+
castcontext => 'a', castmethod => 'f' },
204+
{ castsource => 'regcollation', casttarget => 'int4', castfunc => '0',
205+
castcontext => 'a', castmethod => 'b' },
192206
{ castsource => 'oid', casttarget => 'regtype', castfunc => '0',
193207
castcontext => 'i', castmethod => 'b' },
194208
{ castsource => 'regtype', casttarget => 'oid', castfunc => '0',

‎src/include/catalog/pg_proc.dat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6666,6 +6666,15 @@
66666666
{ oid => '3495', descr => 'convert classname to regclass',
66676667
proname => 'to_regclass', provolatile => 's', prorettype => 'regclass',
66686668
proargtypes => 'text', prosrc => 'to_regclass' },
6669+
{ oid => '4193', descr => 'I/O',
6670+
proname => 'regcollationin', provolatile => 's', prorettype => 'regcollation',
6671+
proargtypes => 'cstring', prosrc => 'regcollationin' },
6672+
{ oid => '4194', descr => 'I/O',
6673+
proname => 'regcollationout', provolatile => 's', prorettype => 'cstring',
6674+
proargtypes => 'regcollation', prosrc => 'regcollationout' },
6675+
{ oid => '4195', descr => 'convert classname to regcollation',
6676+
proname => 'to_regcollation', provolatile => 's', prorettype => 'regcollation',
6677+
proargtypes => 'text', prosrc => 'to_regcollation' },
66696678
{ oid => '2220', descr => 'I/O',
66706679
proname => 'regtypein', provolatile => 's', prorettype => 'regtype',
66716680
proargtypes => 'cstring', prosrc => 'regtypein' },
@@ -7446,6 +7455,12 @@
74467455
{ oid => '2453', descr => 'I/O',
74477456
proname => 'regclasssend', prorettype => 'bytea', proargtypes => 'regclass',
74487457
prosrc => 'regclasssend' },
7458+
{ oid => '4196', descr => 'I/O',
7459+
proname => 'regcollationrecv', prorettype => 'regcollation',
7460+
proargtypes => 'internal', prosrc => 'regcollationrecv' },
7461+
{ oid => '4197', descr => 'I/O',
7462+
proname => 'regcollationsend', prorettype => 'bytea', proargtypes => 'regcollation',
7463+
prosrc => 'regcollationsend' },
74497464
{ oid => '2454', descr => 'I/O',
74507465
proname => 'regtyperecv', prorettype => 'regtype', proargtypes => 'internal',
74517466
prosrc => 'regtyperecv' },

‎src/include/catalog/pg_type.dat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@
379379
typname => 'regclass', typlen => '4', typbyval => 't', typcategory => 'N',
380380
typinput => 'regclassin', typoutput => 'regclassout',
381381
typreceive => 'regclassrecv', typsend => 'regclasssend', typalign => 'i' },
382+
{ oid => '4191', array_type_oid => '4192', descr => 'registered collation',
383+
typname => 'regcollation', typlen => '4', typbyval => 't', typcategory => 'N',
384+
typinput => 'regcollationin', typoutput => 'regcollationout',
385+
typreceive => 'regcollationrecv', typsend => 'regcollationsend', typalign => 'i' },
382386
{ oid => '2206', array_type_oid => '2211', descr => 'registered type',
383387
typname => 'regtype', typlen => '4', typbyval => 't', typcategory => 'N',
384388
typinput => 'regtypein', typoutput => 'regtypeout',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp