Search Postgresql Archives

Re: Multiple tables row insertions from single psql input file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux