pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Shaozhong SHI <shishaozhong@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: parallel-processing multiple similar query tasks - any example?
Date: Thu, 28 Apr 2022 17:17:13 +0200
Message-ID: <202204281517.nznd535364hn@alvherre.pgsql> (raw)
In-Reply-To: <CA+i5Jwa0_9oEPKJUqAi6wLoNzDOiMpD_pLBwEtqtgj48M1Yg3w@mail.gmail.com>

On 2022-Apr-28, Shaozhong SHI wrote:

> multiple similar query tasks are as follows:
> 
> select * from a_table where country ='UK'
> select * from a_table where country='France'
> and so on
> 
> How best to parallel-processing such types of multiple similar query tasks?
> 
> Any example available?

for country in UK France Germany Ireland; do
  echo "select pg_sleep(1); select * from a_table where country = '${country//\'/''/}'"
done | \
  xargs -d"\n" -P10 -n1 psql -X -c

Note the ${country/} stuff is a bash-ism.

-- 
Álvaro Herrera





view thread (9+ messages)  latest in thread

Message-ID: <202204281517.nznd535364hn@alvherre.pgsql>
Permalink:  ../202204281517.nznd535364hn@alvherre.pgsql/
Also on:    postgresql.org/message-id/202204281517.nznd535364hn@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@alvh.no-ip.org, shishaozhong@gmail.com
  Subject: Re: parallel-processing multiple similar query tasks - any example?
  In-Reply-To: <202204281517.nznd535364hn@alvherre.pgsql>
  References: <CA+i5Jwa0_9oEPKJUqAi6wLoNzDOiMpD_pLBwEtqtgj48M1Yg3w@mail.gmail.com> <202204281517.nznd535364hn@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