Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread Ron Johnson
On Mon, Jun 10, 2024 at 5:16 PM David G. Johnston < david.g.johns...@gmail.com> wrote: > On Mon, Jun 10, 2024 at 12:43 PM Ron Johnson >> wrote: > > >> Most useful to you will be some number of "ALTER TABLE DISABLE >> TRIGGER ALL;" statements near the beginning of the file, and their "ALTER >> TA

Re: Multiple tables row insertions from single psql input file [RESOLVED]

2024-06-10 Thread Rich Shepard
On Mon, 10 Jun 2024, David G. Johnston wrote: Values introduces literal records/rows. Rows are written within parentheses. Values (..., ...), (..., ...) You seem to have the closing parenthesis but not the opening one. David, Duh! Of course. For whatever the reason I kept not seeing that. M

Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread David G. Johnston
On Mon, Jun 10, 2024 at 2:58 PM Rich Shepard wrote: > > INSERT into companies (company_nbr,company_name,industry,status) VALUES > nextval('companies_org_nbr_seq'),'Acme','Manufacturing','Opportunity'), > nextval('companies_org_nbr_seq'),'Baker','Livestock','Opportunity'); > > Running: > $ psql -U

Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread Rich Shepard
On Mon, 10 Jun 2024, Peter J. Holzer wrote: My question is whether I can create new rows for all three tables in the same sql source file. Yes, of course. Since the location and contact tables require sequence numbers from the company and location tables is there a way to specify, e.g., cur

Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread Peter J. Holzer
On 2024-06-10 11:50:27 -0700, Rich Shepard wrote: > My business tracking database has three main tables: company, location, > contact. The company and contact primary keys are sequences. > > I've been adding new rows using INSERT INTO files separately for each table > after manually finding the la

Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread David G. Johnston
> > On Mon, Jun 10, 2024 at 12:43 PM Ron Johnson > wrote: > Most useful to you will be some number of "ALTER TABLE DISABLE > TRIGGER ALL;" statements near the beginning of the file, and their "ALTER > TABLE ... ENABLE TRIGGER ALL;" counterparts near the end of the file. > > Have you just not he

Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread Ron Johnson
On Mon, Jun 10, 2024 at 4:06 PM Rich Shepard wrote: > On Mon, 10 Jun 2024, Ron Johnson wrote: > > > With enough clever scripting you can create a .sql file that does almost > > anything. > > Ron, > > My projects don't all use SQL so I'm far from a clever scripter. :-) > No one is born a scripter

Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread Rich Shepard
On Mon, 10 Jun 2024, Torsten Förtsch wrote: Something along these lines perhaps: =# create table a( id bigserial primary key, x text ); CREATE TABLE =# create table b( fk bigint references a(id), y text ); CREATE TABLE =# with ins_a as (insert into a (x) values ('a row') returning *) insert i

Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread Rich Shepard
On Mon, 10 Jun 2024, Ron Johnson wrote: With enough clever scripting you can create a .sql file that does almost anything. Ron, My projects don't all use SQL so I'm far from a clever scripter. :-) Most useful to you will be some number of "ALTER TABLE DISABLE TRIGGER ALL;" statements near

Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread Torsten Förtsch
On Mon, Jun 10, 2024 at 8:50 PM Rich Shepard wrote: > My question is whether I can create new rows for all three tables in the > same sql source file. Since the location and contact tables require > sequence > numbers from the company and location tables is there a way to specify, > e.g., current

Re: Multiple tables row insertions from single psql input file

2024-06-10 Thread Ron Johnson
On Mon, Jun 10, 2024 at 2:50 PM Rich Shepard wrote: > My business tracking database has three main tables: company, location, > contact. The company and contact primary keys are sequences. > > I've been adding new rows using INSERT INTO files separately for each table > after manually finding the

Multiple tables row insertions from single psql input file

2024-06-10 Thread Rich Shepard
My business tracking database has three main tables: company, location, contact. The company and contact primary keys are sequences. I've been adding new rows using INSERT INTO files separately for each table after manually finding the last PK for the company and contact tables. The location tabl