[Zope] next value

rob@mur.org.uk rob@mur.org.uk
Wed, 6 Dec 2000 21:23:51 +0000


Hi

Here's what I use: 

create table customer(
  custid serial primary key,
  name text not null check (char_length(name)>1),
address text,
  code text,
country text,
  telephone text,
  fax text,
  email text,
  private_comments text
);

And the zsql method to insert a customer:

insert into customer
(name, address, code, country, telephone, fax, email, private_comments)
values(
<dtml-sqlvar name type=nb>,
<dtml-sqlvar address type=nb optional>,
<dtml-sqlvar code type=nb optional>,
<dtml-sqlvar country type=nb optional>,
<dtml-sqlvar telephone type=nb optional>,
<dtml-sqlvar fax type=nb optional>,
<dtml-sqlvar email type=nb optional>,
<dtml-sqlvar private_comments type=nb optional>
)
<dtml-var sql_delimiter>
select currval('customer_custid_seq') as custid

By default Postgresql inserts the next value for a serial type if it
is not provided. The last bit of the SQL method returns the id of the
customer just inserted.

Regards

Rob


On Wed, Dec 06, 2000 at 08:17:08PM +0100, Olaf Zanger wrote:
> hi there,
> 
> i work with postgreSQL 7.0.2, ZPyGreSQL and zope 2.2 on suse 7.0 linux
> 
> for a identifier field adr_id:serial i want to automatically insert a
> new number max(adr_id)+1
> 
> how can this be done in an insert into sql statement?
> 
> i tried nextval('adr_adr_id_seq') but get an error message
> 
> any idea?
> 
> olaf
> 
> -- 
> soli-con Engineering Zanger
> Dipl.-Ing. (FH) Olaf Zanger Nusch
> Lorrainestrasse 23
> 3013 Bern / Switzerland
> Fon: +41-31-332 9782
> Mob: +41-76-572 9782
> mailto:info@soli-con.com
> mailto:olaf.zanger@soli-con.com
> http://www.soli-con.com
Content-Description: Visitenkarte für Olaf Zanger


-- 
Rob Murray