SQL from Linux command line

Поиск
Список
Период
Сортировка
От Scott Geller
Тема SQL from Linux command line
Дата
Msg-id AANLkTikRXpEkzPn6n6APdRhaKfk7qMK0KhiU5wJVw_Ss@mail.gmail.com
обсуждение исходный текст
Ответы Re: SQL from Linux command line  (Mladen Gogala <mladen.gogala@vmsinfo.com>)
Re: SQL from Linux command line  (Frank Bax <fbax@sympatico.ca>)
Re: SQL from Linux command line  (Andreas Kretschmer <akretschmer@spamfence.net>)
Список pgsql-novice

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

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Jean-Yves F. Barbier"
Дата:
Сообщение: Re: Storing the data on a portable extenal hard drive
Следующее
От: Mladen Gogala
Дата:
Сообщение: Re: SQL from Linux command line