How to convert column type from varchar to date in PostgreSQL?

前端 未结 4 988
盖世英雄少女心
盖世英雄少女心 2020-12-30 03:21

I have varchar data type column and date data type column.

I have to update varchar column data into date column

相关标签:
4条回答
  • 2020-12-30 04:01
    UPDATE tableName SET dateColumn=to_date(varcharColumn, 'DD MM YYYY')
    

    Assuming you are saving "07 04 2010"

    You can find further examples and explanation in the documentation:

    http://www.postgresql.org/docs/current/interactive/functions-formatting.html

    0 讨论(0)
  • 2020-12-30 04:11

    syntax for typecasting:

    alter table table_name alter column_name 
       type converting_data_type using(column_name::converting_data_type)
    

    converting from varchar to date

    alter table table_name 
      alter column_name type date using(column_name::date)
    
    0 讨论(0)
  • 2020-12-30 04:12
    ALTER TABLE <tablename> ALTER COLUMN <columnname> TYPE DATE 
    using to_date(<columnname>, 'YYYY-MM-DD');
    
    0 讨论(0)
  • 2020-12-30 04:20
    to_date('05 Dec 2000', 'DD Mon YYYY')
    
    0 讨论(0)
提交回复
热议问题