index 84dbee0c41190e71cdf02473d143e5d88f11a3f9..d3947139c07d58276176ea421ca3e8ac3e8a764c 100644 (file)
COERCE_IMPLICIT_CAST,
-1);
if (transform == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("column \"%s\" cannot be cast automatically to type %s",
- colName, format_type_be(targettype)),
- errhint("Specify a USING expression to perform the conversion.")));
+ {
+ /* error text depends on whether USING was specified or not */
+ if (def->cooked_default != NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("result of USING clause for column \"%s\""
+ " cannot be cast automatically to type %s",
+ colName, format_type_be(targettype)),
+ errhint("You might need to add an explicit cast.")));
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("column \"%s\" cannot be cast automatically to type %s",
+ colName, format_type_be(targettype)),
+ /* translator: USING is SQL, don't translate it */
+ errhint("You might need to specify \"USING %s::%s\".",
+ quote_identifier(colName),
+ format_type_with_typemod(targettype,
+ targettypmod))));
+ }
/* Fix collations after all else */
assign_expr_collations(pstate, transform);
index 65274bc26b71cf96a26f92ed08caf294ac1da13b..3ad2c55775c64e61e1f01f8929a04dfb95f5f1c3 100644 (file)
-- Simple tests for alter table column type
alter table foo alter f1 TYPE integer; -- fails
ERROR: column "f1" cannot be cast automatically to type integer
-HINT: Specify a USING expression to perform the conversion.
+HINT: You might need to specify "USING f1::integer".
alter table foo alter f1 TYPE varchar(10);
create table anothertab (atcol1 serial8, atcol2 boolean,
constraint anothertab_chk check (atcol1 <= 3));
alter table anothertab alter column atcol1 type boolean; -- fails
ERROR: column "atcol1" cannot be cast automatically to type boolean
-HINT: Specify a USING expression to perform the conversion.
+HINT: You might need to specify "USING atcol1::boolean".
+alter table anothertab alter column atcol1 type boolean using atcol1::int; -- fails
+ERROR: result of USING clause for column "atcol1" cannot be cast automatically to type boolean
+HINT: You might need to add an explicit cast.
alter table anothertab alter column atcol1 type integer;
select * from anothertab;
atcol1 | atcol2
index b5ee7b087df8cc225f19c0a866558387ae156d9c..29c1875d2eaec34c58be594aa18fc65330e25828 100644 (file)
@@ -1175,6 +1175,7 @@ insert into anothertab (atcol1, atcol2) values (default, false);
select * from anothertab;
alter table anothertab alter column atcol1 type boolean; -- fails
+alter table anothertab alter column atcol1 type boolean using atcol1::int; -- fails
alter table anothertab alter column atcol1 type integer;
select * from anothertab;