代码之家  ›  专栏  ›  技术社区  ›  leontalbot

将字符串数组更新为小写

  •  0
  • leontalbot  · 技术社区  · 6 年前

    这样地 Update all values of a column to lowercase

    数据示例:

    id | tags                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    ---+---------------------------------------------------------------
    58 | 
    87 | {Pasta}
    94 | {trendy,Supper,"Restaurant casual"}
    ...
    
    2 回复  |  直到 6 年前
        1
  •  3
  •   a_horse_with_no_name    6 年前

    您可以将数组强制转换为文本,应用 lower()

    update the_table
      set tags = lower(tags::text)::text[];
    
        2
  •  1
  •   bevan    6 年前

    也许您可以从数组中创建一个字符串,将其小写,然后一次性还原为数组-尝试:

    create table myTest (
    id bigserial primary key,
    arrayText text[]);
    
    insert into myTest (arrayText) values ('{"aPPLE","GRAPE","piNEappLe","CHErry"}');
    select * from myTest;
    update myTest set arrayText = string_to_array(LOWER(array_to_string(arraytext,',')),',') where id = 1;
    select * from myTest;`