Re: Processing data from table using awk.

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: John McKown <john(dot)archie(dot)mckown(at)gmail(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Processing data from table using awk.
Date: 2015-10-06 14:15:46
Message-ID: CANu8FiysrzQ8wvdRBabqjONm4GhpaFRS8wBb4LgJrdLWQpHDSg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Your best bet is something like

#!/bin/bash

get_data ()
{
QRY=$(psql $HOST $PORT $USER $DBNAME <<_QUERY_

\o your_output_file
SELECT col1, col2, ...., coln
FROM your_table
WHERE <blah>;

_QUERY_

)
}

awk <blah> your_table

On Tue, Oct 6, 2015 at 10:04 AM, John McKown <john(dot)archie(dot)mckown(at)gmail(dot)com>
wrote:

> I'm wanting to do some reporting on data which I have an a PostgreSQL
> table. For lack of anything better, I've decided to see if I can do it in
> GNU awk. OK, using Perl with DBI might be a better idea, I'll grant you
> that. Or maybe Python or Ruby (which I don't know). But out of shear
> cussedness, I'm going to see what I can do in gawk. What I don't see is a
> way to get the data out of PostgreSQL and into my awk program. Does anybody
> know of a way to do this, short of "cheating" by using psql? Yes, I know
> that I could do something like (BASH on Linux/Fedora 22 x86_64):
>
> awk -f some-program.awk <(echo 'SELECT a, b, c, d FROM schema.table ORDER
> BY a' | psql dbname)
>
> What I was hoping for was a "Dynamic Extension" (dll) which would allow
> "native" use of PostgreSQL, or may ODBC. But I haven't found any. Have I
> missed anything? If I were to create such a beastie, would it be of any use
> to others? I guess, in this, I'm wondering what "report writer" most are
> using when psql just doesn't have sufficient capability.
>
> Yeah, sometimes I'm just plain stupid & pig headed. But then it will be a
> "leaning experience" (with associated scars, I'm sure).
>
> --
>
> Schrodinger's backup: The condition of any backup is unknown until a
> restore is attempted.
>
> Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be.
>
> He's about as useful as a wax frying pan.
>
> 10 to the 12th power microphones = 1 Megaphone
>
> Maranatha! <><
> John McKown
>

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2015-10-06 14:20:43 Re: Processing data from table using awk.
Previous Message Tom Lane 2015-10-06 14:14:32 Re: Recording exceptions within function (autonomous transactions?)