Re: INSERT requires SERIAL column?

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: <otisg(at)ivillage(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: INSERT requires SERIAL column?
Date: 2002-02-27 07:50:20
Message-ID: GNELIHDDFBOCMGBFGEFOOEJCCBAA.chriskl@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> Hello,
>
> I've got a table with these columns:
>
> user_id SERIAL
> CONSTRAINT pk_user_auth_user_id PRIMARY KEY,
> email VARCHAR(64) NOT NULL UNIQUE ,
> password VARCHAR(16) NOT NULL ,
> status SMALLINT NOT NULL DEFAULT 1
>
> But when I tried using the following INSERT statement I got an
> error about not being able to parse the input.
>
> INSERT INTO user_auth VALUES ('foo(at)example(dot)com', 'password', 1);
>
> psql:../data/user_auth.dat:13: ERROR: pg_atoi: error in
> "foo(at)example(dot)com": can't parse "foo(at)example(dot)com"
>
> So this indicates that an integer was expected as the first value.
>
> In order to get it to do what I want I had to use this:
>
> INSERT INTO user_auth VALUES (nextval('user_auth_user_id_seq'),
> 'foo(at)example(dot)com', 'password', 1);
>
> Question:
> Is this really necessary or am I missing something?
> I thought specifying SERIAL columns is not neccessary in INSERT
> statements.

You need to specify the columns to insert into, skipping over the SERIAL
column:

INSERT INTO user_auth (email, password, status) VALUES ('foo(at)example(dot)com',
'password', 1);

Chris

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Christopher Kings-Lynne 2002-02-27 07:54:28 Re: Err. compiling func. with SET TRANS...
Previous Message otisg 2002-02-27 07:38:56 INSERT requires SERIAL column?