Skip to content

Instantly share code, notes, and snippets.

@xiazhibin
Last active January 18, 2018 08:19
Show Gist options
  • Save xiazhibin/d1a56d88422942398f83264ea5aa5f08 to your computer and use it in GitHub Desktop.
Save xiazhibin/d1a56d88422942398f83264ea5aa5f08 to your computer and use it in GitHub Desktop.
数据库小笔记

select with update 问题

  • 同一个进程对表的同一行select with update是没有问题的
  • 不同进程对表的同一行select with update是会造成lock transaction。要等其中一方commit
  • idle in transaction,如果开启了一个空闲的事务,会有一个超时时间,postgres会断开这个transaction。解决方法是try catch掉,重新commit

数人数,里面可能有重复的

z_uid     c_uid
1 a
1 b
2 m
  • select DISTINCT z_uid from t
  • select count(DISTINCT z_uid) from t
  • select DISTINCT T.z_uid from (select z.uid as z_uid,c.uid as c_uid from z,c) as T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment