Commit 7df49cef authored by Tom Lane's avatar Tom Lane

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 ...
parent 42be2c79
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.75 2008/07/30 17:05:04 tgl Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.76 2008/07/30 19:35:12 tgl Exp $
PostgreSQL documentation
-->
......@@ -535,9 +535,9 @@ CREATE TYPE <replaceable class="parameter">name</replaceable>
<listitem>
<para>
True if this type is a preferred type within its type category,
else false. The default is true (which is appropriate for
all entries in category <literal>U</>, but is usually not
appropriate for new types in other categories &mdash; beware!).
else false. The default is false. Be very careful about creating
a new preferred type within an existing type category, as this
could cause surprising changes in behavior.
</para>
</listitem>
</varlistentry>
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.56 2008/07/30 17:05:04 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.57 2008/07/30 19:35:12 tgl Exp $ -->
<chapter Id="typeconv">
<title>Type Conversion</title>
......@@ -160,25 +160,13 @@ categories</firstterm>, including <type>boolean</type>, <type>numeric</type>,
<type>timespan</type>, <type>geometric</type>, <type>network</type>, and
user-defined. (For a list see <xref linkend="catalog-typcategory-table">;
but note it is also possible to create custom type categories.) Within each
category there are one or more <firstterm>preferred types</firstterm>, which
category there can be one or more <firstterm>preferred types</firstterm>, which
are preferentially selected when there is ambiguity. With careful selection
of preferred types and available implicit casts, it is possible to ensure that
ambiguous expressions (those with multiple candidate parsing solutions) can be
resolved in a useful way.
</para>
<note>
<para>
For what are now historical reasons, types in the <quote>user-defined</>
category are normally always marked as <quote>preferred</>. Since all types
in this category are preferred, the heuristic that favors preferred types
accomplishes nothing, and thus this situation is equivalent to treating them
all as non-preferred. The <quote>preferred</> marking is useful within the
system-defined type categories, and can be useful within custom type
categories.
</para>
</note>
<para>
All type conversion rules are designed with several principles in mind:
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.335 2008/07/30 17:05:04 tgl Exp $
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.336 2008/07/30 19:35:13 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -762,7 +762,7 @@ AddNewRelationType(const char *typeName,
-1, /* internal size (varlena) */
TYPTYPE_COMPOSITE, /* type-type (composite) */
TYPCATEGORY_COMPOSITE, /* type-category (ditto) */
true, /* all composite types are preferred */
false, /* composite types are never preferred */
DEFAULT_TYPDELIM, /* default array delimiter */
F_RECORD_IN, /* input procedure */
F_RECORD_OUT, /* output procedure */
......@@ -941,7 +941,7 @@ heap_create_with_catalog(const char *relname,
-1, /* Internal size (varlena) */
TYPTYPE_BASE, /* Not composite - typelem is */
TYPCATEGORY_ARRAY, /* type-category (array) */
true, /* all array types are preferred */
false, /* array types are never preferred */
DEFAULT_TYPDELIM, /* default array delimiter */
F_ARRAY_IN, /* array input proc */
F_ARRAY_OUT, /* array output proc */
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.120 2008/07/30 17:05:04 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.121 2008/07/30 19:35:13 tgl Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
......@@ -112,7 +112,7 @@ DefineType(List *names, List *parameters)
char *defaultValue = NULL;
bool byValue = false;
char category = TYPCATEGORY_USER;
bool preferred = true;
bool preferred = false;
char delimiter = DEFAULT_TYPDELIM;
char alignment = 'i'; /* default alignment */
char storage = 'p'; /* default TOAST storage method */
......@@ -475,7 +475,7 @@ DefineType(List *names, List *parameters)
-1, /* internal size (always varlena) */
TYPTYPE_BASE, /* type-type (base type) */
TYPCATEGORY_ARRAY, /* type-category (array) */
true, /* all array types are preferred */
false, /* array types are never preferred */
DEFAULT_TYPDELIM, /* array element delimiter */
F_ARRAY_IN, /* input procedure */
F_ARRAY_OUT, /* output procedure */
......@@ -919,7 +919,7 @@ DefineDomain(CreateDomainStmt *stmt)
internalLength, /* internal size */
TYPTYPE_DOMAIN, /* type-type (domain type) */
category, /* type-category */
false, /* domains are never preferred types */
false, /* domain types are never preferred */
delimiter, /* array element delimiter */
inputProcedure, /* input procedure */
outputProcedure, /* output procedure */
......@@ -1032,7 +1032,7 @@ DefineEnum(CreateEnumStmt *stmt)
sizeof(Oid), /* internal size */
TYPTYPE_ENUM, /* type-type (enum type) */
TYPCATEGORY_ENUM, /* type-category (enum type) */
true, /* all enum types are preferred */
false, /* enum types are never preferred */
DEFAULT_TYPDELIM, /* array element delimiter */
F_ENUM_IN, /* input procedure */
F_ENUM_OUT, /* output procedure */
......@@ -1070,7 +1070,7 @@ DefineEnum(CreateEnumStmt *stmt)
-1, /* internal size (always varlena) */
TYPTYPE_BASE, /* type-type (base type) */
TYPCATEGORY_ARRAY, /* type-category (array) */
true, /* all array types are preferred */
false, /* array types are never preferred */
DEFAULT_TYPDELIM, /* array element delimiter */
F_ARRAY_IN, /* input procedure */
F_ARRAY_OUT, /* output procedure */
......
......@@ -12,7 +12,7 @@
* by PostgreSQL
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.498 2008/07/30 17:05:04 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.499 2008/07/30 19:35:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -5780,7 +5780,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
"typmodin::pg_catalog.oid as typmodinoid, "
"typmodout::pg_catalog.oid as typmodoutoid, "
"typanalyze::pg_catalog.oid as typanalyzeoid, "
"'U' as typcategory, true as typispreferred, "
"'U' as typcategory, false as typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
......@@ -5799,7 +5799,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
"typsend::pg_catalog.oid as typsendoid, "
"0 as typmodinoid, 0 as typmodoutoid, "
"typanalyze::pg_catalog.oid as typanalyzeoid, "
"'U' as typcategory, true as typispreferred, "
"'U' as typcategory, false as typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
......@@ -5818,7 +5818,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
"typsend::pg_catalog.oid as typsendoid, "
"0 as typmodinoid, 0 as typmodoutoid, "
"0 as typanalyzeoid, "
"'U' as typcategory, true as typispreferred, "
"'U' as typcategory, false as typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
......@@ -5837,7 +5837,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
"0 as typreceiveoid, 0 as typsendoid, "
"0 as typmodinoid, 0 as typmodoutoid, "
"0 as typanalyzeoid, "
"'U' as typcategory, true as typispreferred, "
"'U' as typcategory, false as typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault "
"FROM pg_catalog.pg_type "
......@@ -5860,7 +5860,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
"0 as typreceiveoid, 0 as typsendoid, "
"0 as typmodinoid, 0 as typmodoutoid, "
"0 as typanalyzeoid, "
"'U' as typcategory, true as typispreferred, "
"'U' as typcategory, false as typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"NULL as typdefaultbin, typdefault "
"FROM pg_type "
......@@ -5883,7 +5883,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
"0 as typreceiveoid, 0 as typsendoid, "
"0 as typmodinoid, 0 as typmodoutoid, "
"0 as typanalyzeoid, "
"'U' as typcategory, true as typispreferred, "
"'U' as typcategory, false as typispreferred, "
"typdelim, typbyval, typalign, typstorage, "
"NULL as typdefaultbin, NULL as typdefault "
"FROM pg_type "
......@@ -5902,7 +5902,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
"0 as typreceiveoid, 0 as typsendoid, "
"0 as typmodinoid, 0 as typmodoutoid, "
"0 as typanalyzeoid, "
"'U' as typcategory, true as typispreferred, "
"'U' as typcategory, false as typispreferred, "
"typdelim, typbyval, typalign, "
"'p'::char as typstorage, "
"NULL as typdefaultbin, NULL as typdefault "
......@@ -6022,8 +6022,8 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
appendStringLiteralAH(q, typcategory, fout);
}
if (strcmp(typispreferred, "f") == 0)
appendPQExpBuffer(q, ",\n PREFERRED = false");
if (strcmp(typispreferred, "t") == 0)
appendPQExpBuffer(q, ",\n PREFERRED = true");
if (typdelim && strcmp(typdelim, ",") != 0)
{
......
......@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.472 2008/07/30 17:05:05 tgl Exp $
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.473 2008/07/30 19:35:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 200807291
#define CATALOG_VERSION_NO 200807301
#endif
This diff is collapsed.
......@@ -20,7 +20,7 @@ CREATE TYPE city_budget (
output = int44out,
element = int4,
category = 'x', -- just to verify the system will take it
preferred = false -- ditto
preferred = true -- ditto
);
-- Test creation and destruction of shell types
CREATE TYPE shell;
......
......@@ -22,7 +22,7 @@ CREATE TYPE city_budget (
output = int44out,
element = int4,
category = 'x', -- just to verify the system will take it
preferred = false -- ditto
preferred = true -- ditto
);
-- Test creation and destruction of shell types
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment