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
#!/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.archie.mckown@xxxxxxxxx> 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.
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.