更新-使用文本的子句未按预期响应

时间:2018-09-11 21:15:29

标签: postgresql

我有一个表,其中包含一个名为'time_source'的列,具有五个潜在值:

“模型”,“国家/地区城市”,“区域”,“更新”和“存储”

我一直在尝试做出一条更新语句,如果time_source是'model',则不会更新date_destination列:

update t_vessel_list_ballast
set date_destination = date_depart + voyage_time
where time_source not like 'model';

但是它没有按我期望的那样工作。相反,即使'model'在time_source中,它也会覆盖date_destination。我尝试过这样的事情:

update t_vessel_list_ballast
set date_destination = date_depart + voyage_time
where time_source like 'country_city'
or time_source like 'region';

但是我仍然得到相同的结果。

模型中没有其他地方可以发生这种情况。

为什么我没有得到我期望的结果?我该如何解决这个问题以获得我想要的东西?

1 个答案:

答案 0 :(得分:0)

我认为使用like时,如果您想匹配行(或不像此处那样匹配行),则还需要在模式上使用%来显示在哪里匹配其他任何行字符。例如,like '%match'将匹配任何以match结尾的字符串,而like 'match%'将匹配以match开头的字符串。您还可以将它们组合以匹配包含like '%match%'匹配项的字符串。

相关问题