pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedStill the problem with the autoincrement field
4+ messages / 4 participants
[nested] [flat]
* Still the problem with the autoincrement field
@ 1998-10-06 09:29 Marc Eggenberger <me@ieo.ch>
1998-10-06 09:57 ` Re: [GENERAL] Still the problem with the autoincrement field Kevin Heflin <kheflin@shreve.net>
1998-10-06 10:08 ` Re: [GENERAL] Still the problem with the autoincrement field Herouth Maoz <herouth@oumail.openu.ac.il>
0 siblings, 2 replies; 4+ messages in thread
From: Marc Eggenberger @ 1998-10-06 09:29 UTC (permalink / raw)
To: pgsql-general@postgresql.org
Hi there.
As two people said I created now a sequence .... I have the following now:
Database = jobforum
+------------------+----------------------------------+----------+
| Owner | Relation | Type |
+------------------+----------------------------------+----------+
| postgres | offene_stellen | table |
| postgres | seq | sequence |
+------------------+----------------------------------+----------+
Table = offene_stellen
+----------------------------------+----------------------------------+-------+
| Field | Type | Length|
+----------------------------------+----------------------------------+-------+
| id | int4 default nextval ( 'seq' ) | 4 |
| bezeichnung | char() | 100 |
| arbeitsort | char() | 100 |
| berater | char() | 100 |
| gefordert | char() | 1000 |
| geboten | char() | 1000 |
+----------------------------------+----------------------------------+-------+
Table = seq
+----------------------------------+----------------------------------+-------+
| Field | Type | Length|
+----------------------------------+----------------------------------+-------+
| sequence_name | name | 32 |
| last_value | int4 | 4 |
| increment_by | int4 | 4 |
| max_value | int4 | 4 |
| min_value | int4 | 4 |
| cache_value | int4 | 4 |
| is_cycled | char | 1 |
| is_called | char | 1 |
+----------------------------------+----------------------------------+-------+
and when I want to add some data .. how to do this?
when I do the following:
insert into offene_stellen values ('', 'Maurer', 'Buchs', 'Rheinhalter Claudio', 'flexibilitaet', 'gutes Team');
the id field is always 0, and when I do a:
insert into offene_stellen values ('Maurer', 'Buchs', 'Rheinhalter Claudio', 'flexibilitaet', 'gutes Team');
I get a:
ERROR: pg_atoi: error in "Maurer": can't parse "Maurer"
How do I add data, so that the id field is autoincremented?
--
mit freundlichen Gruessen
=====================================
Eggenberger Marc me@ieo.ch
Leimbachstr. 56 Tel 01/4802800
8041 Zuerich Fax 01/4802801
=====================================
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [GENERAL] Still the problem with the autoincrement field
1998-10-06 09:29 Still the problem with the autoincrement field Marc Eggenberger <me@ieo.ch>
@ 1998-10-06 09:57 ` Kevin Heflin <kheflin@shreve.net>
1 sibling, 0 replies; 4+ messages in thread
From: Kevin Heflin @ 1998-10-06 09:57 UTC (permalink / raw)
To: Marc Eggenberger <me@ieo.ch>; +Cc: pgsql-general@postgreSQL.org
On Tue, 6 Oct 1998, Marc Eggenberger wrote:
>
> and when I want to add some data .. how to do this?
> when I do the following:
>
> insert into offene_stellen values ('', 'Maurer', 'Buchs', 'Rheinhalter Claudio', 'flexibilitaet', 'gutes Team');
>
> the id field is always 0, and when I do a:
>
> insert into offene_stellen values ('Maurer', 'Buchs', 'Rheinhalter Claudio', 'flexibilitaet', 'gutes Team');
Not exactly sure what the problem is here.. but you should not have to
call on the increment sequence at all durring the insert.. it's automatic
Maybe it's because you are not specifying which fields to insert into like
so:
insert into table_name (field1, field2, field3, field4)
values ('data1', 'data2', 'data3', 'data4');
Kevin
--------------------------------------------------------------------
Kevin Heflin | ShreveNet, Inc. | Ph:318.222.2638 x103
VP/Mac Tech | 333 Texas St #619 | FAX:318.221.6612
kheflin@shreve.net | Shreveport, LA 71101 | http://www.shreve.net
--------------------------------------------------------------------
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [GENERAL] Still the problem with the autoincrement field
1998-10-06 09:29 Still the problem with the autoincrement field Marc Eggenberger <me@ieo.ch>
@ 1998-10-06 10:08 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1 sibling, 0 replies; 4+ messages in thread
From: Herouth Maoz @ 1998-10-06 10:08 UTC (permalink / raw)
To: Marc Eggenberger <me@ieo.ch>; +Cc: pgsql-sql
At 11:29 +0200 on 6/10/98, Marc Eggenberger wrote:
> when I do the following:
>
> insert into offene_stellen values ('', 'Maurer', 'Buchs', 'Rheinhalter
>Claudio', 'flexibilitaet', 'gutes Team');
>
> the id field is always 0, and when I do a:
>
> insert into offene_stellen values ('Maurer', 'Buchs', 'Rheinhalter
>Claudio', 'flexibilitaet', 'gutes Team');
>
> I get a:
> ERROR: pg_atoi: error in "Maurer": can't parse "Maurer"
>
>
> How do I add data, so that the id field is autoincremented?
Simple. NEVER do an insert without mentioning the field names. It is never
advisable to rely on the order of the fields in the database, in any case.
In this case, you simply must not enter a value to the field, so that in
knows that it should insert the default value.
So, what you should do is:
INSERT INTO offene_stellen (
bezeichnung,
arbeitsort,
berater
gefordert
geboten
)
VALUES (
'Maurer',
'Buchs',
'Rheinhalter Claudio',
'flexibilitaet',
'gutes Team'
);
This works, and it also makes sure that if you change the schema such that
the order of the fields is different or there are new fields between the
existing fields, the query won't break.
But if you insist on not mentioning field names, I think inserting a NULL
rather than a value in the id field should work. I won't swear on it, but I
think you should make that field NOT NULL in the table definition.
Remember that '' (The empty string) is NOT THE SAME THING as a NULL. The
empty string is just a string with length 0. NULL is "There is nothing
here".
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] Re: [GENERAL] Still the problem with the autoincrement field
@ 1998-10-06 11:48 James Oden <joden@lee.k12.nc.us>
0 siblings, 0 replies; 4+ messages in thread
From: James Oden @ 1998-10-06 11:48 UTC (permalink / raw)
To: Marc Eggenberger <me@ieo.ch>; Herouth Maoz <herouth@oumail.openu.ac.il>; +Cc: pgsql-sql
|
|So, what you should do is:
|
|INSERT INTO offene_stellen (
| bezeichnung,
| arbeitsort,
| berater
| gefordert
| geboten
|)
|VALUES (
| 'Maurer',
| 'Buchs',
| 'Rheinhalter Claudio',
| 'flexibilitaet',
| 'gutes Team'
|);
|
|This works, and it also makes sure that if you change the schema such that
|the order of the fields is different or there are new fields between the
|existing fields, the query won't break.
Also, if you are working with a program where the user may want to updated
only certain fields you can do that without paying any attention to the
order of the fields in the table. I tried to do it the other way with NULLs
and such, and its just a real hassle once you change the the structure of
the database to go back and make your code conform to the new structure.
|
|But if you insist on not mentioning field names, I think inserting a NULL
|rather than a value in the id field should work. I won't swear on it,
It works, but I definately agree with Herouth...don't do it...its a bad
idea. You will save yourself much work in the long run if you just include
the column names in the update query, and besides if you are embedding this
query in a program there should be no problem at all. You type the query
once, and provided you typed it correctly, forget about it.
...james
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1998-10-06 11:48 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-10-06 09:29 Still the problem with the autoincrement field Marc Eggenberger <me@ieo.ch>
1998-10-06 09:57 ` Kevin Heflin <kheflin@shreve.net>
1998-10-06 10:08 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1998-10-06 11:48 Re: [SQL] Re: [GENERAL] Still the problem with the autoincrement field James Oden <joden@lee.k12.nc.us>
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