Re: multiple sql results to shell

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Mark Lybarger <mlybarger(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: multiple sql results to shell
Date: 2017-10-23 14:19:03
Message-ID: CAKFQuwaJG=_bNXRFfM2k8s9wqWfthx0d99--rU=WZJww15Sirw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Oct 23, 2017 at 7:08 AM, Mark Lybarger <mlybarger(at)gmail(dot)com> wrote:

> I have this bash/sql script which outputs some curl commands. the
> backticks causes it to get interpreted by the shell. This works fine if
> there is one result, but when there are many rows returned, it looks like
> one shell command.
>
> any help on getting multiple rows returned to be executed by the shell
> would be appreciated!
>
> thanks!
>
> `psql -P "tuples_only=on" -h ${DB_HOST} -d ${DB_NAME} -U ${DB_USER} -c
> "select 'curl -X POST http://${REGISTER_HOST}:8080/' || source_id ||
> '/${MT}/' || model || '/' || site || '/backoffice/register' from
> myschema.events where source_id = $SOURCE_ID and ineffective_date is null"`
>
>
​You will need to, instead, "SELECT source_id, model, site​ FROM ..." to
return the raw record data to bash and then use bash's loop facilities to
dynamically generate and execute the curl command.

A second option, that I've never tried, is returning the full string but
not within a backtick command, then using bash looping simply invoke the
string like a normal command.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Geoff Winkless 2017-10-23 14:24:14 Re: multiple sql results to shell
Previous Message Mark Lybarger 2017-10-23 14:08:04 multiple sql results to shell