简体   繁体   English

与PostgreSQL相同的timestamp / rowversion(SQL Server)是什么

[英]What is the equivalent of timestamp/rowversion (SQL Server) with PostgreSQL

Could someone help me find the equivalent of Timestamp/Rowversion (SQL Server) with PostgreSQL? 有人可以帮我找到与PostgreSQL等效的Timestamp / Rowversion(SQL Server)吗?

I'm using NHibernate on Mono (UNIX). 我在Mono上使用NHibernate(UNIX)。

I think that Timestamp (PostgreSQL) is the equivalent of Datetime (SQL Server) - it's not what I'm looking for . 我认为Timestamp(PostgreSQL)相当于Datetime(SQL Server) - 它不是我想要的

Edit 1: For those who don't know what is a Timestamp/Rowversion in SQL Server: http://msdn.microsoft.com/en-us/library/ms182776.aspx (It is mostly used for optimistic concurrency) 编辑1:对于那些不知道SQL Server中什么是Timestamp / Rowversion的人: http//msdn.microsoft.com/en-us/library/ms182776.aspx (它主要用于乐观并发)

See the system columns section in PostgreSQL documentation. 请参阅PostgreSQL文档中的系统列部分。 In particular, xmin might be what you're looking for. 特别是, xmin可能就是你要找的东西。

But be careful using any system columns. 但要小心使用任何系统列。 They are by definition implementation specific and the details of some of them might change with future versions. 根据定义,它们是特定于实现的,其中一些细节可能会随着未来版本而变化。

If I understand correctly rowversion is the same as serial ? 如果我理解正确rowversion与serial相同? If not - you'd have to make your own with triggers. 如果不是 - 你必须使用触发器制作自己的。

You can create it manually: 您可以手动创建它:

  1. Create sequence 创建序列
  2. Create trigger for insert and update for each table that contains rowversion column 为包含rowversion列的每个表创建插入和更新的触发器
  3. Set rowversion column from sequence 从序列中设置rowversion列

The key thing being missed is that rowversion type changed each time there is an update to the row, even if the net result is that, the row is not changed. 错过的关键是每次对行进行更新时都会更改rowversion类型,即使最终结果是行,也不会更改行。

CREATE TABLE MyTest (myKey int PRIMARY KEY  
    ,myValue int, RV rowversion);  
GO   
INSERT INTO MyTest (myKey, myValue) VALUES (1, 0);  
GO   
INSERT INTO MyTest (myKey, myValue) VALUES (2, 0);  
GO  

select * from MyTest
Go

update MyTest set myValue = 0 
go

/* row version will have changed */
select * from MyTest
Go

The only choice I have found is to create an update trigger. 我找到的唯一选择是创建更新触发器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM