Re: no value for numeric filed in SQL statement causes an error

From: Michael Fork <mfork(at)toledolink(dot)com>
To: juerg(dot)rietmann(at)pup(dot)ch
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: no value for numeric filed in SQL statement causes an error
Date: 2001-01-31 14:43:11
Message-ID: Pine.BSI.4.21.0101310934340.16275-100000@glass.toledolink.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

You can do it one of two ways, dynamically build your queries and leave
out fields that are blank (they will be set to the default value or, if
none is specified, NULL), i.e.:

INSERT INTO table (name, city) VALUES ('roger rabbit', 'carrot city');

or, assign a default value to the id variable, and update the variable if
the form field is not blank, leaving you with:

INSERT INTO table (name, id, city) VALUES ('roger rabbit', <<Default ID
Variable or Form Value Variable>>, 'carrot city');

You cannot put a column with any of the number types (int4, numeric,
etc.) into the field list and leave it blank, a value *must* be specified.

Michael Fork - CCNA - MCP - A+
Network Support - Toledo Internet Access - Toledo Ohio

On Wed, 31 Jan 2001 juerg(dot)rietmann(at)pup(dot)ch wrote:

> Hi there
>
> I have a table with char and int fields. From my form I get no values back
> for int fields when they are left blank. This causes the SQL insert to
> fail.
>
> field type
> name char
> id int2
> city char
>
> insert into table (name,id,city) values ('roger rabbit',,'carrot city')
>
> The default for int/float fields is 0. Since I reuse the code of the
> referring page I don't like to have all fields assigned 0 at the beginning.
>
> Who can help ???
>
> Thanks ... jr
>
> ============================================
> PFISTER + PARTNER, SYSTEM - ENGINEERING AG
> Juerg Rietmann
> Grundstrasse 22a
> 6343 Rotkreuz
> Switzerland
>
> phone: +4141 790 4040
> fax: +4141 790 2545
> mobile: +4179 211 0315
> ============================================
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Mark Volpe 2001-01-31 15:10:49 Re: interval query.
Previous Message Ian Harding 2001-01-31 14:35:43 Re: no value for numeric filed in SQL statement causes an error