暂无图片
postgreSQL怎么自动更新时间戳?
我来答
分享
暂无图片 匿名用户
postgreSQL怎么自动更新时间戳?

postgreSQL怎么自动更新时间戳?

我来答
添加附件
收藏
分享
问题补充
1条回答
默认
最新
李宏达
  • 创建表
drop table if exists ts; create table ts ( id bigserial primary key, tradeid integer , email varchar(50), num integer, modified timestamp default current_timestamp );
复制
  • 创建触发器函数
create or replace function upd_timestamp() returns trigger as $$ begin new.modified = current_timestamp; return new; end $$ language plpgsql;
复制
  • 创建触发器
create trigger t_name before update on ts for each row execute procedure upd_timestamp();
复制
  • 测试代码:
insert into ts (tradeid,email,num) values (1223,'mike_zhang@live.com',1); update ts set email='Mike_Zhang@live' where tradeid = 1223 ; create unique index ts_tradeid_idx on ts(tradeid); insert into ts(tradeid,email,num) values (1223,'Mike_Zhang@live.com',2) on conflict(tradeid) do update set email = excluded.email,num=excluded.num; select * from ts;
复制
暂无图片 评论
暂无图片 有用 0
打赏 0
暂无图片
回答交流
Markdown


请输入正文
提交
相关推荐
postgreSQL 分区表到底有没有性能提升?
回答 2
分区后只提升了部分能命中分区规则的SQL性能,对于分区后仍然需要扫描整张表的查询,性能并没有改善。
生产上有没有用到postgreSQL 14版本的吗?
回答 3
我准备过23个月上PG16,数据库上线后更新太麻烦,不如一步到位。
为何 centos-stream/9-stream 只有pg13/15 没有14呢?
回答 1
已采纳
CentOSStream9stream不支持PostgreSQL14,因为它是一个持续发展的发行版,它的目标是提供最新的技术,而不是提供稳定的发行版。PostgreSQL14是一个新的发行版,它还没有
postgresql 中的record能加字段吗?
回答 1
RECORD不是真正的数据类型,只是一个占位符。
pg中如何只用delete from t where id in () 模拟一个死锁的发生?
回答 4
把死锁日志传上来看下?
pg的shema 是不是子模式的概念
回答 1
已采纳
一个数据库包含一个或多个已命名的模式,模式又包含表。模式还可以包含其它对象,包括数据类型、函数、操作符等。同一个对象名可以在不同的模式里使用而不会导致冲突;比如,schema1和myschema都可以
pg中如何查看是否有未决事务??
回答 1
如何确定PostgreSQL中是否存在[空闲连接]未提交的事务?如果要查看有多少具有打开事务的空闲连接,可以使用:selectfrompgstatactivitywhere(state‘idleint
postgresql怎么查行数?
回答 2
count一下这个表。
kingbaseV8R3和postgreSQL哪个版本最接近?
回答 1
已采纳
9.6
这个如何改成pg中的存储过程??
回答 2
createorreplaceprocedureproc01nocommit()as$$declarec01cursorforselectidfromt1;vidinteger;beginopenc0
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~