Home > Net >  I have two table , one staging table and other main table, i need to copy the record of one into oth
I have two table , one staging table and other main table, i need to copy the record of one into oth

Time:07-15

I have a staging table having column 'X' which have 'true' and 'false' value, the datatype of the column is boolean. I created a main table having same column 'X', but want that 'false' be stored a 0 and 'true' as 1, in the main, table. Also, i want to make the datatype of 'X', in main table as 'int2'.

I am using CASE statement. but, its not working.

Please, tell if I can use any other method to achieve it. the code i m using is given below.

(CASE
           WHEN stg.X = 'false' THEN 0
           WHEN stg.X = 'true' THEN 1
           END),  

CodePudding user response:

So, the flaw is with the datatype of the column 'X', in the main table. Instead of the 'boolean data type', I had used 'int2'. The code that I used for the mapping is as below: -

(CASE WHEN stg.X = 'false' THEN 0
        ELSE 1
        END),

CodePudding user response:

Please try below
CASE WHEN stg.x = 'false' THEN 0
ELSE stg.x= 'True' THEN 1
END;

  • Related