Develop/TroubleShooting

error: Missing data for not-null field code: 1213 해결

향식이 2023. 8. 28. 18:05

Situation

Tableau에서 Amazon Redshift를 연결한 후 쿼리를 실행하려고 할때 아래와 같은 오류가 났다. 

 

emergency!! emergency!!

Error: "[Amazon][Redshift ODBC] (30) Error occurred while trying to execute a Query ERROR: Missing data for not-null field DETAIL"(오류: "[Amazon][Redshift ODBC] (30) 쿼리 실행 시 오류 발생 ERROR: null이 아닌 필드 DETAIL에 대한 데이터가 없음") 

"[Amazon][Redshift ODBC] (30) Error occurred while trying to execute a query ERROR: Error converting text to date([Amazon][Redshift ODBC] (30) 쿼리 실행 시 오류 발생. 오류: 텍스트를 날짜로 변환 중 오류 발생)"

 

이는 데이터 원본에 null 필드가 많은 경우, Redshift는 이러한 필드를 빈 문자열("")로 변환하는데 Tableau에서는 CHAR 및 VARCHAR 데이터 유형과 같은 빈 문자열이 처리되지 않기 때문에 오류가 발생하는 것이다. 

 

Solution

Amazon Redshift 데이터 필드를 Null로 유지하도록 해야 한다. 필자는 NULLIF를 이용해서 빈 문자열을 NULL로 변환하도록 쿼리를 추가로 작성했다.
UPDATE public.real_time_data_copy
SET
    col1 = NULLIF(col1, ''),
    col2 = NULLIF(col2, ''),
    co3 = NULLIF(col3, '');

공식 홈페이지에서는 BLANKASNULL함수를 사용하도록 권장하고 있다! 가능하다면 이 함수를 적용해보자 : )

 

참고: https://kb.tableau.com/articles/issue/multiple-amazon-redshift-odbc-30-errors-received-when-trying-to-refresh-an-amazon-redshift-extract?

반응형