Search code examples
timestamplocaleamazon-redshift

AWS Redshift : [Amazon](500339) Unexpected error for TiMESTAMP


Please allow me to ask further question about Redshift TIMESTAMP.

When we select TIMESTAMP field, we get error 500339 or 40483, but with To_Char formula it can return without fail as follows;

-- create test table on Redshift
create table test_datetime (
  a timestamp
);

-- insert test data 
insert into test_datetime values ('20180914 04:05:06.789')

-- get error when you select all that table
select *  from test_dm_dbo.test_datetime
error : [Amazon](500339) Unexpected error consuming date type from server, 
source data: "09/14/2018" 1 statement failed.

-- you can get correctly timestamp data to degignate datetime format 
select to_char(a, 'YYYY-MM-DD HH24:MI:SS') as migrated_dt from test_datetime;

migrated_dt
----------------------
2018-09-14 04:05:06

select to_char(a, 'MM/DD/YYYY HH12:MI:SS') as migrated_dt from test_datetime;

migrated_dt
----------------------
09/14/2018 04:05:06

I imagine our Redshift locale or something is required further setting but I'm not sure what and how should be.

If you have any workaround to avoid this kind of issue, any advice would be so helpful.

Best Regards;


Solution

  • Just F.Y.I., it seems the cause of our issue is 'datestyle'.

    Originally, our datestyle was set as 'SQL, YMD' and returns error even though with simple query as follows;

    show datestyle;
    
    NAME        SETTING
    ------------------------------------
    datestyle   SQL, YMD
    
    -- returns error
    select current_date;
    
    [Amazon](500339) Unexpected error consuming date type from server, source data: "10/04/2018"
    1 statement failed.
    

    With datestyle 'ISO, YMD', the date value is returned without issue any more;

    -- change datestyle
    set datestyle to 'ISO, YMD'
    
    -- returns date value as expected
    select current_date;
    
    DATE
    ------------
    2018-10-04
    

    Thanks for all of your attentions and advices. Hope it would help bit anyone encountering the same kind of issue, especially in non-US region.

    Sincerly,