AdministraĆ§Ć£o do sistema

SQL - Como verificar se existem colunas numeric com valor 'NaN' (PostgreSQL)?

RT.FAQ-10893
Para saber se uma base Eligo tenha alguma coluna do tipo Numeric com valor 'NaN', rodar a seguinte query:

   select count(1) from importacoes_nfe_entrada where icms_sn_valor_credito = 'NaN';
   select count(1) from movimentos_estoques where quantidade = 'NaN';
   select count(1) from doc_entradas_saidas where valor_mercadorias = 'NaN';
   select count(1) from doc_entradas_saidas where valor_taxa_cobranca = 'NaN';
   select count(1) from doc_entradas_saidas where valor_frete = 'NaN';
   select count(1) from doc_entradas_saidas where valor_desconto = 'NaN';
   select count(1) from doc_entradas_saidas where valor_icms = 'NaN';
   select count(1) from doc_entradas_saidas where valor_ipi = 'NaN';
   select count(1) from doc_entradas_saidas where valor_seguro = 'NaN';
   select count(1) from doc_entradas_saidas where valor_base = 'NaN';
   select count(1) from doc_entradas_saidas where valor_isentos = 'NaN';
   select count(1) from doc_entradas_saidas where valor_outros = 'NaN';
   select count(1) from doc_entradas_saidas where valor_frete_conhecimento = 'NaN';
   select count(1) from doc_entradas_saidas where creditos_valores_financeiros = 'NaN';
   select count(1) from doc_entradas_saidas where debitos_valores_financeiros = 'NaN';
   select count(1) from doc_entradas_saidas where valores_bonificacao = 'NaN';
   select count(1) from doc_entradas_saidas where valor_desconto_incondicional = 'NaN';
   select count(1) from doc_entradas_saidas where valor_total = 'NaN';
   select count(1) from doc_entradas_saidas where valor_icms_substituicao = 'NaN';
   select count(1) from doc_entradas_saidas where volume_peso_bruto = 'NaN';
   select count(1) from doc_entradas_saidas where volume_peso_liquido = 'NaN';
   select count(1) from titulos where valor = 'NaN';
   select count(1) from titulos where saldo = 'NaN';
   select count(1) from estoques_produtos where estoque_atual = 'NaN';
   select count(1) from operacoes_fiscais_documentos where valor_ipi = 'NaN';
   select count(1) from operacoes_fiscais_documentos where valor_base = 'NaN';
   select count(1) from operacoes_fiscais_documentos where valor_icms = 'NaN';
   select count(1) from operacoes_fiscais_documentos where valor_isentos = 'NaN';
   select count(1) from operacoes_fiscais_documentos where valor_outros = 'NaN';
   select count(1) from operacoes_fiscais_documentos where valor_contabil = 'NaN';
   select count(1) from operacoes_fiscais_itens_documento where valor_tributo = 'NaN';
   select count(1) from operacoes_fiscais_itens_documento where base_tributo = 'NaN';
   select count(1) from operacoes_fiscais_itens_documento where valor_representado = 'NaN';
   select count(1) from movimentos_financeiros where valor = 'NaN';
   select count(1) from movimentos_financeiros where valor_contabil = 'NaN';
   select count(1) from pedidos where valor_desconto_mercadorias = 'NaN';
   select count(1) from pedidos where valor_desconto_servicos = 'NaN';
   select count(1) from pedidos where valor_franquia = 'NaN';
   select count(1) from itens_pedidos where quantidade_efetiva = 'NaN';
   select count(1) from itens_doc_entradas_saidas_imp_ad where valor_desconto = 'NaN';
   select count(1) from itens_doc_entradas_saidas where quantidade = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_atual_colecao = 'NaN';
   select count(1) from itens_doc_entradas_saidas where aliquota_icms = 'NaN';
   select count(1) from itens_doc_entradas_saidas where saldo_inventario = 'NaN';
   select count(1) from itens_doc_entradas_saidas where saldo_fiscal = 'NaN';
   select count(1) from itens_doc_entradas_saidas where saldo_confirmacao = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_unitario = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_despesas_item = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_credito_icms = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_mercadorias_servicos = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_total_item = 'NaN';
   select count(1) from itens_doc_entradas_saidas where percentual_comissao = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_icms_base = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_icms_isentos = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_icms_outros = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_icms = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_ipi = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_ipi_base = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_ipi_isento = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_ipi_outros = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_desconto_item = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_frete_item = 'NaN';
   select count(1) from itens_doc_entradas_saidas where valor_seguro_item = 'NaN';
   select count(1) from contratos_servicos where valor_unitario_com_desconto = 'NaN';
   select count(1) from contratos_servicos where valor_reembolso = 'NaN';

Para montar o script acima, executar:

   SELECT 'select count(1) from ' || c.table_name || ' where ' || c.column_name || ' = ''NaN'';'
   FROM information_schema.columns c
   JOIN information_schema.tables t on t.table_name = c.table_name
   where data_type='numeric'
   and t.table_type = 'BASE TABLE';