Re: [GENERAL] Still the problem with the autoincrement field

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Marc Eggenberger <me(at)ieo(dot)ch>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Still the problem with the autoincrement field
Date: 1998-10-06 10:08:23
Message-ID: l03110701b23f9a2c84c3@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message James Oden 1998-10-06 11:34:40 Re: [GENERAL] make[2]: *** [psql] Error 1
Previous Message Kevin Heflin 1998-10-06 09:57:01 Re: [GENERAL] Still the problem with the autoincrement field

Browse pgsql-sql by date

  From Date Subject
Next Message James Oden 1998-10-06 11:48:20 Re: [SQL] Re: [GENERAL] Still the problem with the autoincrement field
Previous Message Kevin Heflin 1998-10-06 09:57:01 Re: [GENERAL] Still the problem with the autoincrement field