在 Postgres 9.5 中执行 UPSERT 时,是否可以在 INSERT 成功时返回 null 并在 CONFLICT 时返回某些内容?
我想要这样的东西:
insert into "user" (timestamp, user_id, member_id)
values ($1, $2, $3)
ON CONFLICT (user_id, member_id)
DO select id from "user" where user_id = $2 returning user_id
Run Code Online (Sandbox Code Playgroud)
选择 user_id 的唯一目的是在冲突时返回某些内容(除 null 以外的任何内容),并且不写入磁盘。我知道这可以通过 ON CONFLICT DO UPDATE 来完成,但这会涉及写入磁盘。
在 Postgres 中,如果查询包含在具有可序列化隔离级别的事务中,是否需要使用 FOR UPDATE 锁定表中的行?换句话说,可序列化事务是否会自行锁定行,直到提交事务为止?
Postgres 中以下语句的含义和目的是什么:
xmax::text::int > 0
Run Code Online (Sandbox Code Playgroud)
这看起来像是先转换为文本,然后再次转换为整数???
有没有办法将 Nginx 配置为类似这样的直接服务器返回(DSR)负载均衡器:http :
//blog.haproxy.com/2011/07/29/layer-4-load-balancing-direct-server -返回模式/
PHP session.hash_function使用哪种哈希算法作为默认值?以下页面说默认值为md5"0":http: //php.net/manual/en/session.configuration.php#ini.session.hash-function 但是哈希算法页面显示代码"0"为md2 . http://php.net/manual/en/function.hash-algos.php
如果php.ini上的代码"0"真的对应于md5那么php.ini的其他哈希算法的代码是什么?例如sha512的代码是什么?
在Postgres 9.3中,当表中的字段具有空值时,以下表达式不起作用:
update table_statatistic set members = members + 1 WHERE user_id = $1;
Run Code Online (Sandbox Code Playgroud)
但是,当字段具有整数值时,此查询将其递增1而没有问题.
问题是:
如果$ value大于0,一切正常,但如果$ value设置为0,则case switch打印出Billion :-).
由于手册没有说明值0没有被评估,所以这对我来说是一个麻烦的错误.http://php.net/manual/en/control-structures.switch.php
$value = 0;
switch ($value) {
case $value >= 1000000000:
print 'Billion';
break;
case $value >= 1000000:
print 'Million';
break;
case $value >= 1000 :
print 'Thousand';
break;
default:
print 'Ten';
break;
}
Run Code Online (Sandbox Code Playgroud)
.
Output: Billion :-)
Run Code Online (Sandbox Code Playgroud)