inserting into "date" field returns error (COPY/BINARY)

Поиск
Список
Период
Сортировка
От Konstantin Izmailov
Тема inserting into "date" field returns error (COPY/BINARY)
Дата
Msg-id CAAw-Msd1sywnDkZXwE=jSKjziNJbTWmmdXQT5eLBq1x8E7en0w@mail.gmail.com
обсуждение исходный текст
Ответы Re: inserting into "date" field returns error (COPY/BINARY)
Список pgsql-general
I have implemented a C++ procedure for inserting data using libpq and COPY WITH BINARY command. All field types are working as expected in PG9.2, except "date":
  ERROR:  incorrect binary data format
  CONTEXT:  COPY table, line 1, column date_xyz

The passed value for "date" is a 64-bit integer, calculated by the same way as the value for "timestamp". Should they be different?

Here is simplified fragment of code:
typedef __int64 PGTimeStamp;
...
    pField->dataLength = htonl(sizeof(PGTimeStamp));
    DBTIMESTAMP ts = { 2012, 10, 5, 0, 0, 0, 0 };
    *(PGTimeStamp*)&pField->data = ConvertADOToPG(&ts);
...
PGTimeStamp ConvertADOToPG(DBTIMESTAMP *ts)
{
    double date = date2j(ts->year, ts->month, ts->day) - POSTGRES_EPOCH_JDATE;
    double time = time2t(ts->hour, ts->minute, ts->second, ts->fraction);

    double tmp = date * SECS_PER_DAY + time;

    PGTimeStamp rez;
    int* ptmp = (int*)&tmp;
    int* prez = (int*)&rez;
    prez[0] = htonl(ptmp[1]);
    prez[1] = htonl(ptmp[0]);

    return rez;
}

I'm definitely missing something, please help.

P.S. Documentation mentions about possible compatibility issues. What are those?
TY!

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

Предыдущее
От: Vik Fearing
Дата:
Сообщение: Re: bug in 8.4 and resolved
Следующее
От: Rafał Pietrak
Дата:
Сообщение: Re: using text search