Agent skill
postgres
Queries SQL seguras (read-only)
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/postgres
SKILL.md
Queries SQL seguras (READ-ONLY) no banco do Tá na Mão.
Conexão
Via Docker
docker compose exec db psql -U postgres -d tanamao
Via psql direto
psql "postgresql://postgres:postgres@localhost:5432/tanamao"
Queries de Consulta
Contar Registros
-- Total por tabela
SELECT 'municipios' as tabela, COUNT(*) FROM municipios
UNION ALL
SELECT 'beneficiarios', COUNT(*) FROM beneficiarios
UNION ALL
SELECT 'programas', COUNT(*) FROM programas;
Beneficiários por Programa
SELECT
p.nome as programa,
COUNT(b.id) as total_beneficiarios,
SUM(b.valor) as valor_total
FROM beneficiarios b
JOIN programas p ON b.programa_id = p.id
GROUP BY p.nome
ORDER BY total_beneficiarios DESC;
Buscar por CPF (mascarado)
SELECT
CONCAT('***', RIGHT(cpf, 4)) as cpf_masked,
programa_id,
valor,
data_referencia
FROM beneficiarios
WHERE cpf = '12345678901'
LIMIT 10;
Municípios com Mais Beneficiários
SELECT
m.nome as municipio,
m.uf,
COUNT(b.id) as total
FROM municipios m
LEFT JOIN beneficiarios b ON b.municipio_id = m.id
GROUP BY m.id, m.nome, m.uf
ORDER BY total DESC
LIMIT 20;
Cobertura por Estado
SELECT
m.uf,
COUNT(DISTINCT m.id) as municipios,
COUNT(b.id) as beneficiarios,
SUM(b.valor) as valor_total
FROM municipios m
LEFT JOIN beneficiarios b ON b.municipio_id = m.id
GROUP BY m.uf
ORDER BY m.uf;
Queries de Verificação
Estrutura das Tabelas
\dt -- Listar tabelas
\d beneficiarios -- Estrutura da tabela
\d+ beneficiarios -- Estrutura detalhada
Índices
SELECT indexname, indexdef
FROM pg_indexes
WHERE tablename = 'beneficiarios';
Tamanho das Tabelas
SELECT
relname as tabela,
pg_size_pretty(pg_total_relation_size(relid)) as tamanho
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC;
Regras de Segurança
- Apenas SELECT - Nunca INSERT, UPDATE, DELETE direto
- Mascarar CPF - Usar
RIGHT(cpf, 4)em outputs - Limitar resultados - Sempre usar
LIMIT - Sem exports - Não exportar dados para arquivos
Exemplo com SQLAlchemy (código)
from sqlalchemy import text
async def consultar_beneficiario(session, cpf: str):
query = text("""
SELECT programa_id, valor, data_referencia
FROM beneficiarios
WHERE cpf = :cpf
LIMIT 10
""")
result = await session.execute(query, {"cpf": cpf})
return result.fetchall()
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?