pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Hernan Jesus Gonzalez Carmona <hjgonzalezc@gmail.com>
Cc: pgsql-es-ayuda@lists.postgresql.org
Subject: Re: Exportacion por lotes
Date: Tue, 3 Mar 2020 17:55:22 -0300
Message-ID: <20200303205522.GA1671@alvherre.pgsql> (raw)
In-Reply-To: <CAA_QqyyRu59UpRoNc8uZ9nqhES=Q215iTB4ZPnHe0j2Vf2YTYQ@mail.gmail.com>

On 2020-Mar-03, Hernan Jesus Gonzalez Carmona wrote:

> Estimados antes que todo me presento, mi nombre es Hernan Gonzalez, me
> acabo de inscribir en esta lista de correo y desde ya me disculpo si en
> este mensaje violo alguna normativa de la lista de correo pero necesito
> ayuda que me apura mucho.
> 
> Quien me podria ayudar con información respecto de como exportar una
> consulta en distintos archivos según una condición determinada y que cada
> archivo tenga el nombre de dicha condición, es decir, si tengo una tabla
> con 100 registros y uno de los campos tiene un dominio de 4 valor
> distintos, necesito generar 4 archivos cada uno con nombre de cada valor
> posible de dicho campo, y que la suma de los registros de los 4 archivos
> sea 100

Hernán, tu mensaje no viola ninguna norma, pero la lista pgsql-general
trafica en inglés.  Para preguntas en castellano puedes usar la lista
pgsql-es-ayuda (en copia).

No indicaste qué herramienta quieres usar para lograr tu resultado.
Por ejemplo si puedes usar bash, podrías hacer algo como

#!/bin/bash

valores=$(psql -At --no-psqlrc -c "select distinct valores from tabla")
for i in $valores; do
  psql -At --no-psqlrc -o "resultados-$i.txt" -c "select * from tabla where valores = '$i'"
done

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





view thread (5+ messages)  latest in thread

Message-ID: <20200303205522.GA1671@alvherre.pgsql>
Permalink:  ../20200303205522.GA1671@alvherre.pgsql/
Also on:    postgresql.org/message-id/20200303205522.GA1671@alvherre.pgsql

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: alvherre@2ndquadrant.com, hjgonzalezc@gmail.com, pgsql-es-ayuda@lists.postgresql.org
  Subject: Re: Exportacion por lotes
  In-Reply-To: <20200303205522.GA1671@alvherre.pgsql>
  References: <CAA_QqyyRu59UpRoNc8uZ9nqhES=Q215iTB4ZPnHe0j2Vf2YTYQ@mail.gmail.com> <20200303205522.GA1671@alvherre.pgsql>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox