Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7df49ce

Browse files
committed
Flip the default typispreferred setting from true to false. This affects
only type categories in which the previous coding made *every* type preferred; so there is no change in effective behavior, because the function resolution rules only do something different when faced with a choice between preferred and non-preferred types in the same category. It just seems safer and less surprising to have CREATE TYPE default to non-preferred status ...
1 parent 42be2c7 commit 7df49ce

File tree

9 files changed

+116
-128
lines changed

9 files changed

+116
-128
lines changed

doc/src/sgml/ref/create_type.sgml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.75 2008/07/30 17:05:04 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.76 2008/07/30 19:35:12 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -535,9 +535,9 @@ CREATE TYPE <replaceable class="parameter">name</replaceable>
535535
<listitem>
536536
<para>
537537
True if this type is a preferred type within its type category,
538-
else false. The default is true (which is appropriate for
539-
all entries in category <literal>U</>, but is usually not
540-
appropriate for new types in other categories &mdash; beware!).
538+
else false. The default is false. Be very careful about creating
539+
a new preferred type within an existing type category, as this
540+
could cause surprising changes in behavior.
541541
</para>
542542
</listitem>
543543
</varlistentry>

doc/src/sgml/typeconv.sgml

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.56 2008/07/30 17:05:04 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.57 2008/07/30 19:35:12 tgl Exp $ -->
22

33
<chapter Id="typeconv">
44
<title>Type Conversion</title>
@@ -160,25 +160,13 @@ categories</firstterm>, including <type>boolean</type>, <type>numeric</type>,
160160
<type>timespan</type>, <type>geometric</type>, <type>network</type>, and
161161
user-defined. (For a list see <xref linkend="catalog-typcategory-table">;
162162
but note it is also possible to create custom type categories.) Within each
163-
category there are one or more <firstterm>preferred types</firstterm>, which
163+
category there can be one or more <firstterm>preferred types</firstterm>, which
164164
are preferentially selected when there is ambiguity. With careful selection
165165
of preferred types and available implicit casts, it is possible to ensure that
166166
ambiguous expressions (those with multiple candidate parsing solutions) can be
167167
resolved in a useful way.
168168
</para>
169169

170-
<note>
171-
<para>
172-
For what are now historical reasons, types in the <quote>user-defined</>
173-
category are normally always marked as <quote>preferred</>. Since all types
174-
in this category are preferred, the heuristic that favors preferred types
175-
accomplishes nothing, and thus this situation is equivalent to treating them
176-
all as non-preferred. The <quote>preferred</> marking is useful within the
177-
system-defined type categories, and can be useful within custom type
178-
categories.
179-
</para>
180-
</note>
181-
182170
<para>
183171
All type conversion rules are designed with several principles in mind:
184172

src/backend/catalog/heap.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.335 2008/07/30 17:05:04 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.336 2008/07/30 19:35:13 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -762,7 +762,7 @@ AddNewRelationType(const char *typeName,
762762
-1, /* internal size (varlena) */
763763
TYPTYPE_COMPOSITE, /* type-type (composite) */
764764
TYPCATEGORY_COMPOSITE, /* type-category (ditto) */
765-
true, /* all composite types are preferred */
765+
false, /* composite types are never preferred */
766766
DEFAULT_TYPDELIM, /* default array delimiter */
767767
F_RECORD_IN, /* input procedure */
768768
F_RECORD_OUT, /* output procedure */
@@ -941,7 +941,7 @@ heap_create_with_catalog(const char *relname,
941941
-1, /* Internal size (varlena) */
942942
TYPTYPE_BASE, /* Not composite - typelem is */
943943
TYPCATEGORY_ARRAY, /* type-category (array) */
944-
true, /* all array types are preferred */
944+
false, /* array types are never preferred */
945945
DEFAULT_TYPDELIM, /* default array delimiter */
946946
F_ARRAY_IN, /* array input proc */
947947
F_ARRAY_OUT, /* array output proc */

src/backend/commands/typecmds.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.120 2008/07/30 17:05:04 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.121 2008/07/30 19:35:13 tgl Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -112,7 +112,7 @@ DefineType(List *names, List *parameters)
112112
char *defaultValue = NULL;
113113
bool byValue = false;
114114
char category = TYPCATEGORY_USER;
115-
bool preferred = true;
115+
bool preferred = false;
116116
char delimiter = DEFAULT_TYPDELIM;
117117
char alignment = 'i'; /* default alignment */
118118
char storage = 'p'; /* default TOAST storage method */
@@ -475,7 +475,7 @@ DefineType(List *names, List *parameters)
475475
-1, /* internal size (always varlena) */
476476
TYPTYPE_BASE, /* type-type (base type) */
477477
TYPCATEGORY_ARRAY, /* type-category (array) */
478-
true, /* all array types are preferred */
478+
false, /* array types are never preferred */
479479
DEFAULT_TYPDELIM, /* array element delimiter */
480480
F_ARRAY_IN, /* input procedure */
481481
F_ARRAY_OUT, /* output procedure */
@@ -919,7 +919,7 @@ DefineDomain(CreateDomainStmt *stmt)
919919
internalLength, /* internal size */
920920
TYPTYPE_DOMAIN, /* type-type (domain type) */
921921
category, /* type-category */
922-
false, /* domains are never preferred types */
922+
false, /* domain types are never preferred */
923923
delimiter, /* array element delimiter */
924924
inputProcedure, /* input procedure */
925925
outputProcedure, /* output procedure */
@@ -1032,7 +1032,7 @@ DefineEnum(CreateEnumStmt *stmt)
10321032
sizeof(Oid), /* internal size */
10331033
TYPTYPE_ENUM, /* type-type (enum type) */
10341034
TYPCATEGORY_ENUM, /* type-category (enum type) */
1035-
true, /* all enum types are preferred */
1035+
false, /* enum types are never preferred */
10361036
DEFAULT_TYPDELIM, /* array element delimiter */
10371037
F_ENUM_IN, /* input procedure */
10381038
F_ENUM_OUT, /* output procedure */
@@ -1070,7 +1070,7 @@ DefineEnum(CreateEnumStmt *stmt)
10701070
-1, /* internal size (always varlena) */
10711071
TYPTYPE_BASE, /* type-type (base type) */
10721072
TYPCATEGORY_ARRAY, /* type-category (array) */
1073-
true, /* all array types are preferred */
1073+
false, /* array types are never preferred */
10741074
DEFAULT_TYPDELIM, /* array element delimiter */
10751075
F_ARRAY_IN, /* input procedure */
10761076
F_ARRAY_OUT, /* output procedure */

src/bin/pg_dump/pg_dump.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.498 2008/07/30 17:05:04 tgl Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.499 2008/07/30 19:35:13 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -5780,7 +5780,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
57805780
"typmodin::pg_catalog.oid as typmodinoid, "
57815781
"typmodout::pg_catalog.oid as typmodoutoid, "
57825782
"typanalyze::pg_catalog.oid as typanalyzeoid, "
5783-
"'U' as typcategory, true as typispreferred, "
5783+
"'U' as typcategory, false as typispreferred, "
57845784
"typdelim, typbyval, typalign, typstorage, "
57855785
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
57865786
"FROM pg_catalog.pg_type "
@@ -5799,7 +5799,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
57995799
"typsend::pg_catalog.oid as typsendoid, "
58005800
"0 as typmodinoid, 0 as typmodoutoid, "
58015801
"typanalyze::pg_catalog.oid as typanalyzeoid, "
5802-
"'U' as typcategory, true as typispreferred, "
5802+
"'U' as typcategory, false as typispreferred, "
58035803
"typdelim, typbyval, typalign, typstorage, "
58045804
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
58055805
"FROM pg_catalog.pg_type "
@@ -5818,7 +5818,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
58185818
"typsend::pg_catalog.oid as typsendoid, "
58195819
"0 as typmodinoid, 0 as typmodoutoid, "
58205820
"0 as typanalyzeoid, "
5821-
"'U' as typcategory, true as typispreferred, "
5821+
"'U' as typcategory, false as typispreferred, "
58225822
"typdelim, typbyval, typalign, typstorage, "
58235823
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
58245824
"FROM pg_catalog.pg_type "
@@ -5837,7 +5837,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
58375837
"0 as typreceiveoid, 0 as typsendoid, "
58385838
"0 as typmodinoid, 0 as typmodoutoid, "
58395839
"0 as typanalyzeoid, "
5840-
"'U' as typcategory, true as typispreferred, "
5840+
"'U' as typcategory, false as typispreferred, "
58415841
"typdelim, typbyval, typalign, typstorage, "
58425842
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
58435843
"FROM pg_catalog.pg_type "
@@ -5860,7 +5860,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
58605860
"0 as typreceiveoid, 0 as typsendoid, "
58615861
"0 as typmodinoid, 0 as typmodoutoid, "
58625862
"0 as typanalyzeoid, "
5863-
"'U' as typcategory, true as typispreferred, "
5863+
"'U' as typcategory, false as typispreferred, "
58645864
"typdelim, typbyval, typalign, typstorage, "
58655865
"NULL as typdefaultbin, typdefault "
58665866
"FROM pg_type "
@@ -5883,7 +5883,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
58835883
"0 as typreceiveoid, 0 as typsendoid, "
58845884
"0 as typmodinoid, 0 as typmodoutoid, "
58855885
"0 as typanalyzeoid, "
5886-
"'U' as typcategory, true as typispreferred, "
5886+
"'U' as typcategory, false as typispreferred, "
58875887
"typdelim, typbyval, typalign, typstorage, "
58885888
"NULL as typdefaultbin, NULL as typdefault "
58895889
"FROM pg_type "
@@ -5902,7 +5902,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
59025902
"0 as typreceiveoid, 0 as typsendoid, "
59035903
"0 as typmodinoid, 0 as typmodoutoid, "
59045904
"0 as typanalyzeoid, "
5905-
"'U' as typcategory, true as typispreferred, "
5905+
"'U' as typcategory, false as typispreferred, "
59065906
"typdelim, typbyval, typalign, "
59075907
"'p'::char as typstorage, "
59085908
"NULL as typdefaultbin, NULL as typdefault "
@@ -6022,8 +6022,8 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
60226022
appendStringLiteralAH(q, typcategory, fout);
60236023
}
60246024

6025-
if (strcmp(typispreferred, "f") == 0)
6026-
appendPQExpBuffer(q, ",\n PREFERRED = false");
6025+
if (strcmp(typispreferred, "t") == 0)
6026+
appendPQExpBuffer(q, ",\n PREFERRED = true");
60276027

60286028
if (typdelim && strcmp(typdelim, ",") != 0)
60296029
{

src/include/catalog/catversion.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2008, 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.472 2008/07/30 17:05:05 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.473 2008/07/30 19:35:13 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200807291
56+
#define CATALOG_VERSION_NO 200807301
5757

5858
#endif

0 commit comments

Comments
 (0)