Inserting Default Values

From: Mike Barrett <mike(at)daboyz(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Inserting Default Values
Date: 2002-02-07 17:25:10
Message-ID: Pine.LNX.4.44.0202070918490.12436-100000@loki.daboyz.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all. I just started using postgres for a website I'm writing,
and so I was messing around with some of it's features and I'm running
into a little problem.
Pretty much, it has to do with default values on the first column
of a row.

Say I have a table that looks like the following:

[Table name 'test']
name | character varying(16) |
id | integer | not null default
nextval('"test_id_seq"'::text)

If I run:

sql=> insert into test values('blah');

It inserts just fine, automatically taking the default value for
id. However, the table I'm actually using is the reverse of the previous.
Example:

[Table name 'status']
id | integer | not null default
nextval('"status_id_seq"'::text)
name | character varying(32) |

The problem here is that no matter what I do, I can't get it to
just take the default value for id. I've tried leaving a blank, followed
by a comma as in:

sql=> insert into test values (,'blah');

But that errors out. I've messed with using the nextval()
function, but that seems to run before the actual query is run, so if
there is an error in the query, my sequence goes to the next value
anyways. This won't work for me because if the query fails, I don't want
to have gaps in id #'s.

Anyways, does anyone have any idea how to get around this problem?
Any help you could give me would be great. Thanks.

________________________________________________________________________
Mike Barrett | "I used to read, now I go to raves."
mike(at)daboyz(dot)org | -- Random MUNI Rider, speaking
www.daboyz.org | to my friend Allison.
------------------------+-----------------------------------------------

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-02-07 17:28:51 Re: 7.1.3 : copy from stdin is very slow!
Previous Message Doug McNaught 2002-02-07 17:18:18 Re: Inserting Default Values