pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
id field error
4+ messages / 3 participants
[nested] [flat]

* id field error
@ 2002-04-25 20:00  angelo.rigo@globo.com
  0 siblings, 3 replies; 4+ messages in thread

From: angelo.rigo@globo.com @ 2002-04-25 20:00 UTC (permalink / raw)
  To: pgsql-php

Hi !
I´m doing my first publishing system for a last aquired boooks for a library.

the problem begin in the id field, wich i choose to be primary key and unique.
i could just insert data one time the others give me this error:

 Cannot insert a duplicate key into unique index biblioteca_pkey

i use this piece of code below to insert the data:

$query = "INSERT INTO biblioteca (id, autor, titulo, editora) values ('$id',
'$autor', '$titulo', '$editora')";
$result = pg_exec($db, $query);

may i can alter the id collumn and the query to insert the data anybody
knows what exactly to do ?

Thank´s

Ângelo




________________________________________
A busca mais veloz e precisa da internet. Acesse agora: http://www.zoom.com.br.




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: id field error
@ 2002-04-25 20:34  Jeff Self <jself@nngov.com>
  parent: angelo.rigo@globo.com
  2 siblings, 0 replies; 4+ messages in thread

From: Jeff Self @ 2002-04-25 20:34 UTC (permalink / raw)
  To: angelo.rigo@globo.com; +Cc: pgsql-php

On Thu, 2002-04-25 at 16:00, angelo.rigo@globo.com wrote:
> Hi !
> I´m doing my first publishing system for a last aquired boooks for a library.
> 
> the problem begin in the id field, wich i choose to be primary key and unique.
> i could just insert data one time the others give me this error:
> 
>  Cannot insert a duplicate key into unique index biblioteca_pkey
> 
> i use this piece of code below to insert the data:
> 
> $query = "INSERT INTO biblioteca (id, autor, titulo, editora) values ('$id',
> '$autor', '$titulo', '$editora')";
> $result = pg_exec($db, $query);
> 
> may i can alter the id collumn and the query to insert the data anybody
> knows what exactly to do ?
> 
> Thank´s
> 
> Ângelo
> 

Design your table so that id is of type serial. This lets it
auto-increment the idea. Then do this:

$query = "INSERT INTO biblioteca (autor, titulo, editora)
	values ('$autor', '$titulo', '$editora')";
$result = pg_exec($db, $query);

-- 
Jeff Self
Information Technology Analyst
Department of Personnel
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: id field error
@ 2002-04-26 22:05  Surojit Niyogi <surojit@bungeecode.com>
  parent: angelo.rigo@globo.com
  2 siblings, 0 replies; 4+ messages in thread

From: Surojit Niyogi @ 2002-04-26 22:05 UTC (permalink / raw)
  To: angelo.rigo@globo.com; +Cc: pgsql-php

You can either use the datatype "SERIAL" or if you have a way of 
generating unique IDs based off of microtimes, you can get away with 
putting a unique value into field "id" as it is right now.

Roj Niyogi
pgHoster
PostgreSQL web hosting

angelo.rigo@globo.com wrote:

>Hi !
>I´m doing my first publishing system for a last aquired boooks for a library.
>
>the problem begin in the id field, wich i choose to be primary key and unique.
>i could just insert data one time the others give me this error:
>
> Cannot insert a duplicate key into unique index biblioteca_pkey
>
>i use this piece of code below to insert the data:
>
>$query = "INSERT INTO biblioteca (id, autor, titulo, editora) values ('$id',
>'$autor', '$titulo', '$editora')";
>$result = pg_exec($db, $query);
>
>may i can alter the id collumn and the query to insert the data anybody
>knows what exactly to do ?
>
>Thank´s
>
>Ângelo
>
>
>
>
>________________________________________
>A busca mais veloz e precisa da internet. Acesse agora: http://www.zoom.com.br.
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>
>  
>





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: id field error
@ 2002-04-26 22:05  Surojit Niyogi <surojit@bungeecode.com>
  parent: angelo.rigo@globo.com
  2 siblings, 0 replies; 4+ messages in thread

From: Surojit Niyogi @ 2002-04-26 22:05 UTC (permalink / raw)
  To: angelo.rigo@globo.com; +Cc: pgsql-php

You can either use the datatype "SERIAL" or if you have a way of 
generating unique IDs based off of microtimes, you can get away with 
putting a unique value into field "id" as it is right now.

Roj Niyogi
pgHoster
PostgreSQL web hosting

angelo.rigo@globo.com wrote:

>Hi !
>I´m doing my first publishing system for a last aquired boooks for a library.
>
>the problem begin in the id field, wich i choose to be primary key and unique.
>i could just insert data one time the others give me this error:
>
> Cannot insert a duplicate key into unique index biblioteca_pkey
>
>i use this piece of code below to insert the data:
>
>$query = "INSERT INTO biblioteca (id, autor, titulo, editora) values ('$id',
>'$autor', '$titulo', '$editora')";
>$result = pg_exec($db, $query);
>
>may i can alter the id collumn and the query to insert the data anybody
>knows what exactly to do ?
>
>Thank´s
>
>Ângelo
>
>
>
>
>________________________________________
>A busca mais veloz e precisa da internet. Acesse agora: http://www.zoom.com.br.
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>
>  
>





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2002-04-26 22:05 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-25 20:00 id field error angelo.rigo@globo.com
2002-04-25 20:34 ` Jeff Self <jself@nngov.com>
2002-04-26 22:05 ` Surojit Niyogi <surojit@bungeecode.com>
2002-04-26 22:05 ` Surojit Niyogi <surojit@bungeecode.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox