Check a whole table for a single value

前端 未结 2 1795
栀梦
栀梦 2021-01-23 01:46

Background: I\'m converting a database table to a format that doesn\'t support null values. I want to replace the null values with an arbitrary number so my ap

2条回答
  •  心在旅途
    2021-01-23 02:26

    create or replace function test_values( real ) returns setof record as
    $$
    declare
    query text;
    output record;
    begin
    for query in select 'select distinct ''' || table_name || '''::text table_name, ''' || column_name || '''::text column_name from '|| quote_ident(table_name)||' where ' || quote_ident(column_name) || ' = ''' || $1::text  ||'''::' || data_type  from information_schema.columns where table_schema='public'   and numeric_precision is not null
    loop
        raise notice '%1 qqqq', query;
        execute query::text into output;
        return next output;
    end loop;
    return;
    end;$$ language plpgsql;
    
    select distinct * from test_values( 999999 ) as t(table_name text ,column_name text)
    

提交回复
热议问题