简体   繁体   中英

Cannot convert type date to integer using liquibase

I'm trying to change date type in my Postgsql DB to integer one using this changeset:

--changeset Sihem:001
ALTER TABLE training 
  ALTER COLUMN end_date TYPE integer USING end_date::integer; 

But I got an error: could not convert type date to integer. Any idea please?

You can't. However, you could convert to, say, a number of days since some base date:

using extract(epoch from (end_date - '1970-01-01'::date))

I resolve it by:

 ALTER TABLE training
    ALTER COLUMN end_date TYPE integer USING (EXTRACT(ISOYEAR FROM end_date));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM