bpchar convertion to date during import

45 views Asked by At

I would like to convert bpchar to date during import from the other database. To create an external table it should be matched with the parameters of the table in the other database. Finally, I need the simple table with the column with date type, not bpchar

For example:

  1. table to be imported
CREATE TABLE example (
    mouse bpchar(4),
    "date" bpchar(10),
    quantity int4
);
  1. external table should be like the first one
  2. the final table should be
CREATE TABLE example (
    mouse bpchar(4),
    "date" date,
    quantity int4
);

date format 31.01.2021

i tried simple conversion to date ::date

but it was an error in the create statement

1

There are 1 answers

4
Luuk On

Providing all contents of the field "date" has valid dates, you can create a new table like this:

CREATE TABLE newexample AS 
SELECT mouse, to_date("date",'DD.MM.YYYY'), quantity FROM example;

see: DBFIDDLE