Re: Multiple tables row insertions from single psql input file
От | Rich Shepard |
---|---|
Тема | Re: Multiple tables row insertions from single psql input file |
Дата | |
Msg-id | 153620cc-69f4-d850-ae36-2224dbd7f5ae@appl-ecosys.com обсуждение исходный текст |
Ответ на | Re: Multiple tables row insertions from single psql input file ("Peter J. Holzer" <hjp-pgsql@hjp.at>) |
Ответы |
Re: Multiple tables row insertions from single psql input file
|
Список | pgsql-general |
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., current_val 'tablename PK' for the related tables? > You will of course have to enter each company before its location and each > company and location before its contact. Otherwise you won't have a value > to insert into the foreign key field(s). Peter, That's what I thought was the case; no way to insert new rows in children tables when the parent is having new rows at the same time. So, I started with the parent (companies) table but psql is telling me there's a syntax error and I don't see it. Testing script: 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 rshepard -d bustrac -f test-script.sql psql:test-script.sql:3: ERROR: syntax error at or near "nextval" LINE 2: nextval('companies_org_nbr_seq'),'Acme','Manufacturing','Opp... ^ What have I missed? TIA, Rich
В списке pgsql-general по дате отправления: