Skip site navigation (1) Skip section navigation (2)

Re: SQL from Linux command line

From: Scott Geller <geller(dot)subscribe(at)gmail(dot)com>
To: Mladen Gogala <mladen(dot)gogala(at)vmsinfo(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: SQL from Linux command line
Date: 2010-07-10 20:02:50
Message-ID: AANLkTinkPz3-rkAC_K2iDjZROLulDGIEFSsycbcTm8KI@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Thanks Mladen

I'm a novice - if psgl is not a scripting language, can you please give me
an example of one?  maybe perl?

Thanks


On Sat, Jul 10, 2010 at 7:03 AM, Mladen Gogala <mladen(dot)gogala(at)vmsinfo(dot)com>wrote:

> Scott Geller wrote:
>
>>
>> Hello
>>
>> Hoping for some help on this one....
>>
>> I need to query postgres, run a count of _specific _records, and write to
>> a different table based on the results all from the linux command line.
>>
>> This feels like it should be simple, but I'm new to postgres and could use
>> some help.
>> I'm good with the SQL part - for the SQL, I would write:
>>
>>    create table2 as select *, case when _cnt_ < 50 then 'low' when
>>    _cnt_ >= 50 'high' end as cnt from (select id, count(*) as _cnt_
>>    from table1 where id = 1234 group by id) a;
>>
>> My questions are:
>>
>>   1. Would I use psql for this?
>>   2. If so, how do I structure the script to run psql from Linux?
>>   3. how do I pass the value for the where clause from the command
>>
>>      line into the code?
>>
>> Thanks!
>>
>> Scott
>>
>>  My advice would be simple: use your favorite scripting language for that.
> The  ad hoc query tools like psql are not meant for reporting and batch
> jobs. I've seen such tools abused  so many times that I lost count. What
> people end up with is a lousy report with an unintelligible "script" that
> produces it. The script is hard to maintain, depends on the version and is
> usually longer than a comparable scripting language script.
>
> --
> Mladen Gogala Sr. Oracle DBA
> 1500 Broadway
> New York, NY 10036
> (212) 329-5251
> www.vmsinfo.com
>

In response to

Responses

pgsql-novice by date

Next:From: Mladen GogalaDate: 2010-07-10 22:22:17
Subject: Re: SQL from Linux command line
Previous:From: Donn WashburnDate: 2010-07-10 17:00:23
Subject: postgresql and pgadmin3

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group