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

2018-11-02 Thread Rich Shepard
On Thu, 1 Nov 2018, Ken Tanzer wrote: 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: Ken, Thank

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

2018-11-01 Thread Ken Tanzer
On Thu, Nov 1, 2018 at 5:08 PM Rich Shepard 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.

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

2018-11-01 Thread Rich Shepard
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

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

2018-11-01 Thread Rich Shepard
On Fri, 2 Nov 2018, Tim Cross wrote: 3. Is it really insert or update you need? Tim, Update. It's been a long time since I did any database manipulation (I just use the existing databases as each project needs its data) so I sometimes make these types of mistakes. Your idea of

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

2018-11-01 Thread Tim Cross
Rich Shepard writes: > On Thu, 1 Nov 2018, Adrian Klaver wrote: > >>> alter table stations add column start_date date; >>> alter table stations add column end_date date; >>> alter table stations add column howmany integer; >>> alter table stations add column bin_col char(8); >>> >>> insert

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

2018-11-01 Thread Rich Shepard
On Thu, 1 Nov 2018, Adrian Klaver wrote: Why? As David said that will get you an additional 82 rows with data that is dissociated from the existing data. You want to update the existing rows with the new field data for each station. D'oh! Of course! Thanks both, Rich

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

2018-11-01 Thread Adrian Klaver
On 11/1/18 1:53 PM, Rich Shepard wrote: On Thu, 1 Nov 2018, David G. Johnston wrote: That makes no sense to me...you already have 82 rows on the table so if you insert 82 more you'll have 164 which doesn't seem like what you would want... I would probably do: David,   The table already

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

2018-11-01 Thread Rich Shepard
On Thu, 1 Nov 2018, David G. Johnston wrote: That makes no sense to me...you already have 82 rows on the table so if you insert 82 more you'll have 164 which doesn't seem like what you would want... I would probably do: David, The table already exists with four attribute columns and their

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

2018-11-01 Thread Rich Shepard
On Thu, 1 Nov 2018, Adrian Klaver wrote: alter table stations add column start_date date; alter table stations add column end_date date; alter table stations add column howmany integer; alter table stations add column bin_col char(8); insert into stations (start_date, end_date, howmany,

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

2018-11-01 Thread Adrian Klaver
On 11/1/18 1:23 PM, Rich Shepard wrote:   I have the following code in a script: alter table stations add column start_date date; alter table stations add column end_date date; alter table stations add column howmany integer; alter table stations add column bin_col char(8); insert into

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

2018-11-01 Thread David G. Johnston
On Thu, Nov 1, 2018 at 1:26 PM Rich Shepard wrote: >I have the following code in a script: > > alter table stations add column start_date date; > alter table stations add column end_date date; > alter table stations add column howmany integer; > alter table stations add column bin_col

Add columns to table; insert values based on row

2018-11-01 Thread Rich Shepard
I have the following code in a script: alter table stations add column start_date date; alter table stations add column end_date date; alter table stations add column howmany integer; alter table stations add column bin_col char(8); insert into stations (start_date, end_date, howmany,