Skip to content

Commit e292dbc

Browse files
committed
More sensible character_octet_length
For character types with typmod, character_octet_length columns in the information schema now show the maximum character length times the maximum length of a character in the server encoding, instead of some huge value as before.
1 parent 788d8e5 commit e292dbc

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 $1 IN (25, 1042, 1043) /* text, char, varchar */
107-
THEN CAST(2^30 AS integer)
107+
THEN CASE WHEN $2 = -1 /* default typmod */
108+
THEN CAST(2^30 AS integer)
109+
ELSE information_schema._pg_char_max_length($1, $2) * pg_catalog.pg_encoding_max_length((SELECT encoding FROM pg_database WHERE datname = current_database()))
110+
END
108111
ELSE null
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+
int encoding = PG_GETARG_INT32(0);
489+
490+
if (PG_VALID_ENCODING(encoding))
491+
return pg_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-
#define CATALOG_VERSION_NO 200904091
56+
#define CATALOG_VERSION_NO 200907071
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(insert OID = 1597 ( pg_encoding_to_char PGNSP PGUID 12 1 0 0 f f f t f s 1 0 19 "23" _null_ _null_ _null_ _null_ PG_encoding_to_char _null_ _null_ _null_ ));
22792279
DESCR("convert encoding id to encoding name");
22802280

2281+
DATA(insert OID = 2319 ( pg_encoding_max_length PGNSP PGUID 12 1 0 0 f f f t f i 1 0 23 "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(insert OID = 1638 ( oidgt PGNSP PGUID 12 1 0 0 f f f t f i 2 0 16 "26 26" _null_ _null_ _null_ _null_ oidgt _null_ _null_ _null_ ));
22822285
DESCR("greater-than");
22832286
DATA(insert OID = 1639 ( oidge PGNSP PGUID 12 1 0 0 f f f t f i 2 0 16 "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
extern Datum pg_convert_to(PG_FUNCTION_ARGS);
949949
extern Datum pg_convert_from(PG_FUNCTION_ARGS);
950950
extern Datum length_in_encoding(PG_FUNCTION_ARGS);
951+
extern Datum pg_encoding_max_length_sql(PG_FUNCTION_ARGS);
951952

952953
/* format_type.c */
953954
extern Datum format_type(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy