Strange behavior in Redshift when using time column in a table definition

0

Hi!

I observe a strange behavior in Redshift when adding a time column to an existing table. For example, the following works just fine, i.e. i can create a table with not null time column and specify '00:00:00' literal as column default value:

CREATE TABLE IF NOT EXISTS [dwh].[dim_app_installs_test](
    [id] INT NOT NULL IDENTITY(1, 1) PRIMARY KEY ENCODE zstd
    ,[batch_run_id] INT NOT NULL ENCODE zstd
    ,[install_date] DATE NOT NULL ENCODE raw
    ,[install_time] TIME NOT NULL DEFAULT '00:00:00' ENCODE zstd
    ,[user_id] VARCHAR(36) NOT NULL ENCODE zstd
)
DISTSTYLE KEY
DISTKEY([user_id])
SORTKEY([install_date]);

However, if i try to add a new not null time column with the same definition to an existing table, it gives an error:

CREATE TABLE IF NOT EXISTS [dwh].[dim_app_installs_test](
    [id] INT NOT NULL IDENTITY(1, 1) PRIMARY KEY ENCODE zstd
    ,[batch_run_id] INT NOT NULL ENCODE zstd
    ,[install_date] DATE NOT NULL ENCODE raw
    ,[user_id] VARCHAR(36) NOT NULL ENCODE zstd
)
DISTSTYLE KEY
DISTKEY([user_id])
SORTKEY([install_date]);

ALTER TABLE [dwh].[dim_app_installs_test] ADD COLUMN [install_time] TIME NOT NULL DEFAULT '00:00:00' ENCODE zstd;

Error: Invalid column type for the target column.

What is going on here? Why does it work in the first case and fails in the second? How to fix it?

질문됨 4달 전135회 조회
2개 답변
0
수락된 답변

This seems like a bug or something. Kindly report it via support ticket for proper investigation and next steps.

profile pictureAWS
답변함 4달 전
profile picture
전문가
검토됨 한 달 전
0

Another strange thing about time data type. For example, this update query works fine (assuming install time is of type TIME):

UPDATE [dwh].[dim_app_installs]
SET
    [install_time] = t.[servertime]::time
FROM [staging].[app_install] t 
WHERE 1 = 1
    AND [origin_id] = t.[id];

Also, this update query works fine:

UPDATE [dwh].[dim_app_installs]
SET
    [install_time] = t.[servertime]
FROM [dwh].[dim_app_installs] d
JOIN [staging].[app_install] t ON d.[origin_id] = t.[id];

However, adding explicit cast to TIME to the query above is not working, while it worked in the first query just fine:

UPDATE [dwh].[dim_app_installs]
SET
    [install_time] = t.[servertime]::time
FROM [dwh].[dim_app_installs] d
JOIN [staging].[app_install] t ON d.[origin_id] = t.[id];

ERROR: Target table must be part of an equijoin predicate.

Why is that so? All three queries are equivalent, i think.

답변함 4달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠