匹配的正则表达式以

时间:2017-03-17 15:48:43

标签: regex postgresql

我需要将表设置属性MATCH更新为True,其中attribute_a STARTS的值为attribute_b。

不知怎的,我无法在Postgresql中获得正确的语法来进行这种模式匹配。

UPDATE table   
   SET  match= True  
WHERE attribute_a ~ '^attribute_b' ;

例如MATCH TRUE:attribute_a = Nelson Mandela; attribute_b ='尼尔森'

1 个答案:

答案 0 :(得分:3)

您不需要模式匹配,请使用left(),例如:

<script>
  (function() {
    var name = 'foo';
  })();
  console.log(window.name); // what ever it was before this function call
</script>

如果您绝对想要使用正则表达式,则必须使用with my_table(attribute_a, attribute_b) as ( values ('Nelson Mandela', 'Nelson'), ('Donald Trump', 'Donald Duck'), ('John Major', 'John M') ) select * from my_table where attribute_b = left(attribute_a, length(attribute_b)); attribute_a | attribute_b ----------------+------------- Nelson Mandela | Nelson John Major | John M (2 rows) concat()构建模式,如下所示:

format()
相关问题