Lookup CNPJ
View or edit on GitHub
This page is synchronized from trase/models/brazil/beef/Lookup CNPJ.ipynb. Last modified on 2026-03-21 22:30 CET by Trase Admin.
Please view or edit the original file there; changes should be reflected here after a midnight build (CET time),
or manually triggering it with a GitHub action (link).
import pandas as pd
from trase.config import postgres_dsn
from psycopg2 import sql, connect
cnpjs = ["67620377000890"]
values = sql.SQL(",").join([sql.SQL("({})").format(sql.Literal(c)) for c in cnpjs])
pd.read_sql(
sql.SQL(
"""
with cnpjs(cnpj) as ( values {} )
select * from public.cnpj_2019
join cnpjs using (cnpj)
"""
).format(values),
connect(dsn=postgres_dsn()),
)
print(
sql.SQL(
"""
with cnpjs(cnpj) as ( values {} )
select * from public.cnpj_2019
join cnpjs using (cnpj)
"""
)
.format(values)
.as_string(connect(dsn=postgres_dsn()))
)