using Clause is used when modifying the table field type , Type of conversion for display .
1. Build table
create table t(id integer);2. insert data
insert into t select generate_series(1,10);3. hold id Change the column type to varchar
test=# alter table t alter id type varchar;
ALTER TABLE
because integer turn varchar There are implicit conversions , So it can be automatically converted .4. hold id Change column type back integer
test=# alter table t alter id type integer;
error : Field "id" Cannot be automatically converted to type integer
Tips : You may need to specify "USING id::integer".
stay oracle Under Mode varchar To integer Of cast function , So there's no mistake . The above error is in pg Generated in mode .5. Use Using Clause to cast
test=# alter table t alter id type integer using id::integer;
ALTER TABLEWhen converting types, there is implicit type conversion , It will automatically switch , without , Then you have to use using Specify the conversion rules .




![[AUTOSAR twelve mode management]](/img/42/292e3da3f5d488a1e8c10ea9bbfbab.png)



