Re: Better way to process records in bash?

From: Christoph Moench-Tegeder <cmt(at)burggraben(dot)net>
To: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Better way to process records in bash?
Date: 2024-09-12 19:30:44
Message-ID: ZuNBZM2BB62qvO29@elch.exwg.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

## Ron Johnson (ronljohnsonjr(at)gmail(dot)com):

> I need to process table records in a bash script. Currently, I read them
> using a while loop and redirection. The table isn't that big (30ish
> thousand rows), and performance is adequate, but am always looking for
> "better".

Use python, or any other sane language, and don't do bash in python.
Anything non-trivial is unreasonably hard to get really right when
using shell.

Take this example (even when allowing some fuzz with the variables):
> Here's the current code:
> declare f1 f3 f8
> while IFS='|' read f1 f3 f8; do
> something f8 f3 f1
> done < <(psql -XAt -c "select f1, f3, f8 from some.table_name;")

What happens when f3
a) is NULL?
b) contains a '|' character?
c) contains spaces? (this one depends on how exactly you're handling
the shell variables).
This might be fine if your data is only NOT NULL numbers, but that's
already quite a limitation on your data.

Regards,
Christoph

--
Spare Space

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Florents Tselai 2024-09-12 19:43:56 Re: Better way to process records in bash?
Previous Message Koen De Groote 2024-09-12 18:47:21 Re: Logical replication without direct link between publisher and subscriber?