jsf80238
jsf80238

Reputation: 1673

Default value for TIMESTAMP column

This DDL:

CREATE TABLE example (
  my_stamp TIMESTAMP_NTZ NOT NULL DEFAULT CURRENT_TIMESTAMP(0)
)

Yields this error:

SQL compilation error: Default value data type does not match data type for column MY_STAMP

Changing CURRENT_TIMESTAMP(0) to CURRENT_TIMESTAMP makes the error "go away". Yet, this command returns successfully:

select CURRENT_TIMESTAMP(0), CURRENT_TIMESTAMP;

Upvotes: 0

Views: 1643

Answers (1)

Mike Walton
Mike Walton

Reputation: 7339

This would also work, I believe. You just need to cast the output of the function to the same timestamp data type as the my_stamp column:

CREATE TABLE example (
  my_stamp TIMESTAMP_NTZ NOT NULL DEFAULT CURRENT_TIMESTAMP(0)::TIMESTAMP_NTZ
)

Upvotes: 1

Related Questions