我正在尝试更新所有以’agg%’和column_name=’%userid%’之类的字符串开头的表…但是即使我能够找到选择具有特定列的所有表的选项,我也看不到在线的此类示例名称和表名称我需要执行相同的操作来更新这些表,如下所示:
update TABLE_NAME set COLUMN_NAME='rajeev' WHERE COLUMN_NAME LIKE '%userid%' and TABLE_NAME LIKE 'agg%' FROM INFORMATION_SCHEMA.COLUMNS;
帮助将不胜感激。
谢谢。
获取您条件的更新查询
select 'update '||c.table_name||' set '||c.COLUMN_NAME||' = ''rajeev'';' as my_update_query from (select table_name,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where table_name LIKE 'agg%' and COLUMN_NAME LIKE '%userid%') c
执行
do $$ declare arow record; begin for arow in select 'update '||c.table_name||' set '||c.COLUMN_NAME||' = ''rajeev'';' as my_update_query from (select table_name,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where table_name LIKE 'agg%' and COLUMN_NAME LIKE '%userid%') c loop execute arow.my_update_query; end loop; end; $$;