Re: Add columns to table; insert values based on row

Поиск
Список
Период
Сортировка
От Ken Tanzer
Тема Re: Add columns to table; insert values based on row
Дата
Msg-id CAD3a31WvNSh9AyK-aN2Cmy2TZB_14_jcEuQ8=EB+Zqf_kzFM+g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Add columns to table; insert values based on row  (Rich Shepard <rshepard@appl-ecosys.com>)
Ответы Re: Add columns to table; insert values based on row  (Rich Shepard <rshepard@appl-ecosys.com>)
Список pgsql-general
On Thu, Nov 1, 2018 at 5:08 PM Rich Shepard <rshepard@appl-ecosys.com> wrote:
On Thu, 1 Nov 2018, Rich Shepard wrote:

> I'll use gawk to extract the relevant fields from the text file in which
> they reside (in the correct order), then use emacs keyboard macros to add
> the appropriate update text to each line. Must more efficient (and less
> tedious) than manually writing each line.

   Actually a one-liner gawk script does the job.

I'm not sure what format your text file is in, but you could probably use \copy to bring it into a (temporary) table in Postgres.  As long as it had your four new columns and the site_nbr, you could then update from that table in one swoop:

UPDATE stations
SET start_date=new_data.start_date,
end_date=...
FROM new_data
WHERE stations.site_nbr=new_data.site_nbr;

Cheers,
Ken


--
AGENCY Software  
A Free Software data system
By and for non-profits
(253) 245-3801

learn more about AGENCY or
follow the discussion.

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

Предыдущее
От: Stephen Frost
Дата:
Сообщение: Re: Truncation of UNLOGGED tables upon restart.
Следующее
От: Achilleas Mantzios
Дата:
Сообщение: Re: Copy data from DB2 (Linux) to PG