Coder Social home page Coder Social logo

Comments (2)

ppKrauss avatar ppKrauss commented on August 18, 2024

Cuidado, incluir ordenada,

COPY (
  SELECT c.name, c.state, c.wdid as "wdId", c.idibge as "idIBGE", 
       c.lexlabel as "lexLabel", c.creation, c.extinction, 
       c.postalcode_ranges as "postalCode_ranges", 
       ddd.ddd, c.notes
  FROM dataset.vw8_anatel_ddd as ddd RIGHT JOIN dataset.vw2_br_city_codes c
     ON c.state=ddd.uf AND c.lexlabel=ddd.namelex  -- or synonym!
  ORDER BY std_collate(name), name, state,3
) TO '/tmp/test.csv' CSV HEADER;

E fica ainda pendente o tratamento de sinônimos

from city-codes.

ppKrauss avatar ppKrauss commented on August 18, 2024

Concluído com sinônimos:

-- SOLUCAO correta fazendo inclusão da resolução por sinônimo:
COPY (
  WITH dd AS (
    SELECT DISTINCT c.name, c.state, ddd.ddd
    FROM dataset.vw8_anatel_ddd as ddd 
      INNER JOIN dataset.vw2_br_city_codes_tojoin_synonyms c
      ON c.state=ddd.uf AND c.lexlabel_join=ddd.namelex AND NOT(c.is_original)
  )
  SELECT name, state, wdid as "wdId", idibge as "idIBGE",
       lexlabel as "lexLabel", creation, extinction,
       postalcode_ranges as "postalCode_ranges",
       CASE WHEN ddd IS NULL -- tenta resolver por sinônimo
            THEN (SELECT ddd FROM dd WHERE dd.name=t.name AND dd.state=t.state)
            ELSE ddd
       END,
       notes
  FROM (
     SELECT c.name, c.state, c.wdid, c.idibge, c.lexlabel, c.creation, c.extinction,
       c.postalcode_ranges, ddd.ddd, c.notes
     FROM dataset.vw8_anatel_ddd as ddd RIGHT JOIN dataset.vw2_br_city_codes c
       ON c.state=ddd.uf AND c.lexlabel=ddd.namelex
  ) t ORDER BY std_collate(name), name, state, 3
) TO '/tmp/test_good.csv' CSV HEADER;

from city-codes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.