Skip site navigation (1) Skip section navigation (2)

Re: Multi table insert

From: "George Pavlov" <gpavlov(at)mynewplace(dot)com>
To: "norman" <norman_khine(at)yahoo(dot)co(dot)uk>,<pgsql-novice(at)postgresql(dot)org>
Subject: Re: Multi table insert
Date: 2006-10-27 13:33:22
Message-ID: 8C5B026B51B6854CBE88121DBF097A8655C56A@ehost010-33.exch010.intermedia.net (view raw or flat)
Thread:
Lists: pgsql-novice
can you replace:

  business_name_business_name_seq.last_value

with:

  (select last_value from business_name_business_name_seq)

or, more defensively coded:

  (select max(last_value) from business_name_business_name_seq)

i am assuming business_name_business_name_seq is some kind of one-row
table that is always guaranteed (how?) to have one row and sort of fakes
a sequence (which brings the question of why not use a true sequence?)


> -----Original Message-----
> From: pgsql-novice-owner(at)postgresql(dot)org 
> [mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of norman
> Sent: Friday, October 27, 2006 5:08 AM
> To: pgsql-novice(at)postgresql(dot)org
> Subject: [NOVICE] Multi table insert
> 
> Hello,
> I have created a multi-table insert script in python, the 
> problem is that this worked fine on an older PostgreSQL db 
> (7.2) but now I get an
> 
> Error, psycopg2.ProgrammingError: missing FROM-clause entry 
> for table "business_name_business_name_seq"
> 
> Here is part of the script
> 
> It is a Z SQL Method for Zope.
> 
> ##########
> 
> 
> INSERT INTO business_name (business_name, business_url, 
> business_type_id)
>   values (<dtml-sqlvar business_name type="string" >, 
> <dtml-sqlvar business_url type="string">, <dtml-sqlvar 
> business_type_list_id type="int">);
> 
> <dtml-var sql_delimiter>
> 
> INSERT INTO business_address (street_name, town, city, 
> postcode, county_id, business_name_id) values 
> (<dtml-sqlvar street_name type="string">,
> <dtml-sqlvar town type="string">,
> <dtml-sqlvar city type="string">, 
> <dtml-sqlvar postcode type="string">,
> <dtml-sqlvar county_list type="int">,
> business_name_business_name_seq.last_value);
> 
> #########
> 
> Here I want to take the last_value for the business_name_id 
> that was generated in the first insert and put it as the 
> related item in the next INSERT table.
> 
> Is there a better way to do this? I have 4 tables all related 
> and one input form.
> 
> Many thanks
> 
> Norman
> 

In response to

Responses

pgsql-novice by date

Next:From: normanDate: 2006-10-27 13:49:30
Subject: Re: Multi table insert
Previous:From: shaik mastan dilshadDate: 2006-10-27 12:38:51
Subject: Re: Copying data from table to table (cloned tables)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group