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

Commite292dbc

Browse files
committed
More sensible character_octet_length
For character types with typmod, character_octet_length columns in theinformation schema now show the maximum character length times themaximum length of a character in the server encoding, instead of somehuge value as before.
1 parent788d8e5 commite292dbc

File tree

6 files changed

+37
-18
lines changed

6 files changed

+37
-18
lines changed

‎doc/src/sgml/information_schema.sgml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.39 2009/06/10 07:03:34 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/information_schema.sgml,v 1.40 2009/07/07 18:23:13 petere Exp $ -->
22

33
<chapter id="information-schema">
44
<title>The Information Schema</title>
@@ -343,10 +343,10 @@
343343
<entry><type>cardinal_number</type></entry>
344344
<entry>
345345
If <literal>data_type</literal> identifies a character type,
346-
the maximum possible length in octets (bytes) of a datum (this
347-
should not be of concern to
348-
<productname>PostgreSQL</productname> users); null for all
349-
other data types.
346+
the maximum possible length in octets (bytes) of a datum; null
347+
for all other data types. The maximum octet length depends on
348+
the declared character maximum length (see above) and the
349+
server encoding.
350350
</entry>
351351
</row>
352352

@@ -947,9 +947,10 @@
947947
<entry><type>cardinal_number</type></entry>
948948
<entry>
949949
If <literal>data_type</literal> identifies a character type,
950-
the maximum possible length in octets (bytes) of a datum (this
951-
should not be of concern to <productname>PostgreSQL</productname> users); null for all
952-
other data types.
950+
the maximum possible length in octets (bytes) of a datum; null
951+
for all other data types. The maximum octet length depends on
952+
the declared character maximum length (see above) and the
953+
server encoding.
953954
</entry>
954955
</row>
955956

@@ -1688,9 +1689,9 @@
16881689
<entry><type>cardinal_number</type></entry>
16891690
<entry>
16901691
If the domain has a character type, the maximum possible length
1691-
in octets (bytes) of a datum (this should not be of concern to
1692-
<productname>PostgreSQL</productname> users); null for all
1693-
other data types.
1692+
in octets (bytes) of a datum; null for all other data types.
1693+
The maximum octet length depends on the declared character
1694+
maximum length (see above) and the server encoding.
16941695
</entry>
16951696
</row>
16961697

‎src/backend/catalog/information_schema.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 2003-2009, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.54 2009/06/10 07:03:34 petere Exp $
7+
* $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.55 2009/07/07 18:23:13 petere Exp $
88
*/
99

1010
/*
@@ -104,7 +104,10 @@ CREATE FUNCTION _pg_char_octet_length(typid oid, typmod int4) RETURNS integer
104104
AS
105105
$$SELECT
106106
CASE WHEN $1IN (25,1042,1043)/* text, char, varchar*/
107-
THEN CAST(2^30ASinteger)
107+
THEN CASE WHEN $2=-1/* default typmod*/
108+
THEN CAST(2^30ASinteger)
109+
ELSEinformation_schema._pg_char_max_length($1, $2)*pg_catalog.pg_encoding_max_length((SELECT encodingFROM pg_databaseWHERE datname= current_database()))
110+
END
108111
ELSEnull
109112
END$$;
110113

‎src/backend/utils/mb/mbutils.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Tatsuo Ishii
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.87 2009/06/11 14:49:05 momjian Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.88 2009/07/07 18:23:14 petere Exp $
88
*/
99
#include"postgres.h"
1010

@@ -482,6 +482,17 @@ length_in_encoding(PG_FUNCTION_ARGS)
482482

483483
}
484484

485+
Datum
486+
pg_encoding_max_length_sql(PG_FUNCTION_ARGS)
487+
{
488+
intencoding=PG_GETARG_INT32(0);
489+
490+
if (PG_VALID_ENCODING(encoding))
491+
returnpg_wchar_table[encoding].maxmblen;
492+
else
493+
PG_RETURN_NULL();
494+
}
495+
485496
/*
486497
* convert client encoding to server encoding.
487498
*/

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.531 2009/06/11 14:49:09 momjian Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.532 2009/07/07 18:23:14 petere Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200904091
56+
#defineCATALOG_VERSION_NO200907071
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.544 2009/06/11 14:49:09 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.545 2009/07/07 18:23:14 petere Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -2278,6 +2278,9 @@ DESCR("convert encoding name to encoding id");
22782278
DATA(insertOID=1597 (pg_encoding_to_charPGNSPPGUID12100ffftfs1019"23"_null__null__null__null_PG_encoding_to_char_null__null__null_ ));
22792279
DESCR("convert encoding id to encoding name");
22802280

2281+
DATA(insertOID=2319 (pg_encoding_max_lengthPGNSPPGUID12100ffftfi1023"23"_null__null__null__null_pg_encoding_max_length_sql_null__null__null_ ));
2282+
DESCR("maximum octet length of a character in an eocidng");
2283+
22812284
DATA(insertOID=1638 (oidgtPGNSPPGUID12100ffftfi2016"26 26"_null__null__null__null_oidgt_null__null__null_ ));
22822285
DESCR("greater-than");
22832286
DATA(insertOID=1639 (oidgePGNSPPGUID12100ffftfi2016"26 26"_null__null__null__null_oidge_null__null__null_ ));

‎src/include/utils/builtins.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.332 2009/03/09 14:34:34 petere Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.333 2009/07/07 18:23:15 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -948,6 +948,7 @@ extern Datum pg_convert(PG_FUNCTION_ARGS);
948948
externDatumpg_convert_to(PG_FUNCTION_ARGS);
949949
externDatumpg_convert_from(PG_FUNCTION_ARGS);
950950
externDatumlength_in_encoding(PG_FUNCTION_ARGS);
951+
externDatumpg_encoding_max_length_sql(PG_FUNCTION_ARGS);
951952

952953
/* format_type.c */
953954
externDatumformat_type(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp