pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Marc Eggenberger <me@ieo.ch>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [GENERAL] Still the problem with the autoincrement field
Date: Tue, 6 Oct 1998 12:08:23 +0200
Message-ID: <l03110701b23f9a2c84c3@[147.233.159.109]> (raw)
In-Reply-To: <199810060930.LAA10725@linux1.ieo.ch>

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





view thread (4+ messages)  latest in thread

Message-ID: <l03110701b23f9a2c84c3@[147.233.159.109]>
Permalink:  ../l03110701b23f9a2c84c3@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03110701b23f9a2c84c3@[147.233.159.109]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: herouth@oumail.openu.ac.il, me@ieo.ch
  Subject: Re: [GENERAL] Still the problem with the autoincrement field
  In-Reply-To: <l03110701b23f9a2c84c3@[147.233.159.109]>
  References: <199810060930.LAA10725@linux1.ieo.ch> <l03110701b23f9a2c84c3@[147.233.159.109]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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