From: | Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com> |
---|---|
To: | rshepard(at)appl-ecosys(dot)com |
Cc: | PG-General Mailing List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Add columns to table; insert values based on row |
Date: | 2018-11-02 01:34:47 |
Message-ID: | CAD3a31WvNSh9AyK-aN2Cmy2TZB_14_jcEuQ8=EB+Zqf_kzFM+g@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Nov 1, 2018 at 5:08 PM Rich Shepard <rshepard(at)appl-ecosys(dot)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
*http://agency-software.org/ <http://agency-software.org/>*
*https://demo.agency-software.org/client
<https://demo.agency-software.org/client>*
ken(dot)tanzer(at)agency-software(dot)org
(253) 245-3801
Subscribe to the mailing list
<agency-general-request(at)lists(dot)sourceforge(dot)net?body=subscribe> to
learn more about AGENCY or
follow the discussion.
From | Date | Subject | |
---|---|---|---|
Next Message | Achilleas Mantzios | 2018-11-02 07:01:06 | Re: Copy data from DB2 (Linux) to PG |
Previous Message | Stephen Frost | 2018-11-02 00:52:23 | Re: Truncation of UNLOGGED tables upon restart. |