Tuesday, December 07, 2010

Using Teradata's CURRENT_TIMESTAMP(n)

CURRENT_TIMESTAMP can take an argument stating the precision. This allows the result to easily be passed to a column with matching precision.

CREATE MULTISET TABLE test1,
    
NO FALLBACK,
    
NO BEFORE JOURNAL,
    
NO AFTER JOURNAL (
    
id          INT           NOT NULL,
    
start_dtm0  TIMESTAMP(0)  NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    
start_dtm1  TIMESTAMP(1)  NOT NULL DEFAULT CURRENT_TIMESTAMP(1),
    
start_dtm2  TIMESTAMP(2)  NOT NULL DEFAULT CURRENT_TIMESTAMP(2),
    
start_dtm3  TIMESTAMP(3)  NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    
start_dtm4  TIMESTAMP(4)  NOT NULL DEFAULT CURRENT_TIMESTAMP(4),
    
start_dtm5  TIMESTAMP(5)  NOT NULL DEFAULT CURRENT_TIMESTAMP(5),
    
start_dtm6  TIMESTAMP(6)  NOT NULL DEFAULT CURRENT_TIMESTAMP(6)
);


Results:

Column Value
start_dtm0 12/07/2010 3:10:30
start_dtm1 12/07/2010 3:10:30.8
start_dtm2 12/07/2010 3:10:30.82
start_dtm3 12/07/2010 3:10:30.820
start_dtm4 12/07/2010 3:10:30.8200
start_dtm5 12/07/2010 3:10:30.82000
start_dtm6 12/07/2010 3:10:30.820000

No comments:

Post a Comment