if (transform == NULL)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("column \"%s\" cannot be cast to type %s",
- colName, format_type_be(targettype))));
+ errmsg("column \"%s\" cannot be cast automatically to type %s",
+ colName, format_type_be(targettype)),
+ errhint("Specify a USING expression to perform the conversion.")));
/* Fix collations after all else */
assign_expr_collations(pstate, transform);
if (defaultexpr == NULL)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("default for column \"%s\" cannot be cast to type %s",
+ errmsg("default for column \"%s\" cannot be cast automatically to type %s",
colName, format_type_be(targettype))));
}
else
-- Simple tests for alter table column type
alter table foo alter f1 TYPE integer; -- fails
-ERROR: column "f1" cannot be cast to type integer
+ERROR: column "f1" cannot be cast automatically to type integer
+HINT: Specify a USING expression to perform the conversion.
alter table foo alter f1 TYPE varchar(10);
create table anothertab (atcol1 serial8, atcol2 boolean,
constraint anothertab_chk check (atcol1 <= 3));
(2 rows)
alter table anothertab alter column atcol1 type boolean; -- fails
-ERROR: column "atcol1" cannot be cast to type boolean
+ERROR: column "atcol1" cannot be cast automatically to type boolean
+HINT: Specify a USING expression to perform the conversion.
alter table anothertab alter column atcol1 type integer;
select * from anothertab;
atcol1 | atcol2
alter table anothertab alter column atcol1 type boolean
using case when atcol1 % 2 = 0 then true else false end; -- fails
-ERROR: default for column "atcol1" cannot be cast to type boolean
+ERROR: default for column "atcol1" cannot be cast automatically to type boolean
alter table anothertab alter column atcol1 drop default;
alter table anothertab alter column atcol1 type boolean
using case when atcol1 % 2 = 0 then true else false end; -- fails