SQL Server: Cannot Insert an Explicit Value into a Timestamp Column

SQL Server: Cannot insert an explicit value into a timestamp column

According to MSDN, timestamp

Is a data type that exposes automatically generated, unique binary
numbers within a database. timestamp is generally used as a mechanism
for version-stamping table rows. The storage size is 8 bytes. The
timestamp data type is just an incrementing number and does not
preserve a date or a time. To record a date or time, use a datetime
data type.

You're probably looking for the datetime data type instead.

SQLAlchemy fails to insert timestamp into MSSQL

So, thanks to these fine gentleman out there @LaugingVergil and @HaleemurAli I've just decided to add another sed hack to my dockerfile...

I just do RUN sed -i 's/TIMESTAMP/DateTime/g' /usr/lib/python3.4/site-packages/luigi/db_task_history.py before CMD /usr/bin/luigid

Get inserted timestamp

The problem is that TIMESTAMP is a data type that is automatically generated and only exposed as read-only. It's based around an incrementing number within the system.

SQL Server: Cannot insert an explicit value into a timestamp column

Try this:

DECLARE @table TABLE(id INT, val TIMESTAMP NOT NULL)
DECLARE @table2 TABLE(val DATETIME)

INSERT @table (id)
OUTPUT inserted.val INTO @table2(val)
VALUES (1)

SELECT
t.id,
t.val,
CONVERT( TIMESTAMP, t2.val ) AS table2_timestamp
FROM
@table AS t,
@table2 AS t2


Related Topics



Leave a reply



Submit