Re: Problem while inserting a varchar

Поиск
Список
Период
Сортировка
От Michael Glaesemann
Тема Re: Problem while inserting a varchar
Дата
Msg-id 977C991E-0060-4FD6-9739-F5487211DB4F@seespotcode.net
обсуждение исходный текст
Ответ на Problem while inserting a varchar  (Christian Stalp <christian.stalp@gmx.de>)
Список pgsql-novice
On Feb 17, 2008, at 13:30 , Christian Stalp wrote:

> My insert string looks as follows:  INSERT INTO RETRY VALUES
> ( '0:40:f4:d3:0:0','0:40:f4:d3:0:0',1, 2008-02-17,18:42:05 );
>
> and the postgres-log tells me anything about a invalid input syntax
> for the whole number »0:40:f4:d3:0:0«

The basic problem is that you're not explicitly listing your insert
columns. Postgres is interpreting this:

> INSERT INTO RETRY VALUES ( '0:40:f4:d3:0:0','0:40:f4:d3:0:0',1,
> 2008-02-17,18:42:05 );

as

INSERT INTO RETRY
   (rid, source_macaddress, destination_macaddress, accesspoint,
retray_day)
   VALUES ( '0:40:f4:d3:0:0','0:40:f4:d3:0:0',1,
'2008-02-17','18:42:05' );

(btw, the insert you provide won't actually work, as you're not
quoting your date and time data. It's much better to supply actual
queries, data, and error messages so we can really see what's
happening.)

What you're trying to do is

INSERT INTO RETRY
   (source_macaddress, destination_macaddress, accesspoint, retray_day)
   VALUES ( '0:40:f4:d3:0:0','0:40:f4:d3:0:0',1,
'2008-02-17','18:42:05');

or

INSERT INTO RETRY  VALUES (DEFAULT, '0:40:f4:d3:0:0','0:40:f4:d3:0:0',
1, '2008-02-17','18:42:05');

In general, it's good to explicitly list the insert columns to
prevent exactly this issue.

Btw, why are you using separate date and time fields, rather than
using a timestamp?

Michael Glaesemann
grzm seespotcode net



В списке pgsql-novice по дате отправления:

Предыдущее
От: Christian Stalp
Дата:
Сообщение: Problem while inserting a varchar
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Problem while inserting a varchar