id field error
am 25.04.2002 22:00:04 von angelo.rigo
Hi !
I=B4m doing my first publishing system for a last aquired boooks for a libr=
ary.
the problem begin in the id field, wich i choose to be primary key and uniq=
ue.
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 =3D "INSERT INTO biblioteca (id, autor, titulo, editora) values ('$i=
d',
'$autor', '$titulo', '$editora')";
$result =3D 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=B4s
=C2ngelo
________________________________________
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
Re: id field error
am 25.04.2002 22:34:35 von Jeff Self
On Thu, 2002-04-25 at 16:00, angelo.rigo@globo.com wrote:
> Hi !
> I=B4m doing my first publishing system for a last aquired boooks for a li=
brary.
>=20
> the problem begin in the id field, wich i choose to be primary key and un=
ique.
> i could just insert data one time the others give me this error:
>=20
> Cannot insert a duplicate key into unique index biblioteca_pkey
>=20
> i use this piece of code below to insert the data:
>=20
> $query =3D "INSERT INTO biblioteca (id, autor, titulo, editora) values ('=
$id',
> '$autor', '$titulo', '$editora')";
> $result =3D pg_exec($db, $query);
>=20
> may i can alter the id collumn and the query to insert the data anybody
> knows what exactly to do ?
>=20
> Thank=B4s
>=20
> =C2ngelo
>=20
Design your table so that id is of type serial. This lets it
auto-increment the idea. Then do this:
$query =3D "INSERT INTO biblioteca (autor, titulo, editora)
values ('$autor', '$titulo', '$editora')";
$result =3D pg_exec($db, $query);
--=20
Jeff Self
Information Technology Analyst
Department of Personnel
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/users-lounge/docs/faq.html
Re: id field error
am 27.04.2002 00:05:26 von Surojit Niyogi
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
>
>
>
>
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly
Re: id field error
am 27.04.2002 00:05:43 von Surojit Niyogi
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
>
>
>
>
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)