Home > Mobile >  Casting to char as Integer
Casting to char as Integer

Time:02-21

I'm trying to do some casting but cannot understand where I'm making a mistake. The error occurs in this line:

set  datekey = cast(to_char((event_time)::TIMESTAMP,'yyyymmdd') as integer)

ERROR: Syntax error at »yyyymmdd« LINE 16: ... datekey = cast(to_char((event_time)::TIMESTAMP,'yyyymmdd')...

And here is my whole query:

do $$
  declare
    arow record;
    curtable varchar(50);
    number_ int = 0;
  begin
    for arow in
      SELECT table_name as fact_table FROM information_schema.tables WHERE table_name like 'fact_entriesexits%' 
    loop
      curtable := arow.fact_table;

     RAISE NOTICE 'Updating partition(%)', curtable;
      execute ('
     
            Update ' || curtable || ' e
            set  datekey = cast(to_char((event_time)::TIMESTAMP,'yyyymmdd') as integer),
             timekey = cast(to_char((event_time)::TIMESTAMP,'hhmiss') as integer),
             dateinserted = odb_created_at,
             devicetype = device_type,
             cardnumber = card_nr,
             manufacturerkey = 
                 case when manufacturer like '           
  • Related