From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Stephen Frost <sfrost(at)snowman(dot)net> |
Cc: | pgsql-patches(at)postgresql(dot)org |
Subject: | Re: Add error-checking to timestamp_recv |
Date: | 2004-05-20 15:47:21 |
Message-ID: | 200405201547.i4KFlLn15309@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
Stephen Frost wrote:
> > So you are passing the data via binary COPY or a C function?
>
> Sorry I wasn't clear, it's using libpq and binary data using an 'insert'
> statement. The code looks something like this:
>
> PQexec(connection,"prepare addrow (timestamp) as insert into mytable
> values ($1)");
> lengths[0] = sizeof(double);
> formats[0] = 1;
> *(double*)(values[0]) = tv_sec - ((POSTGRES_EPOCH_JDATE -
> UNIX_EPOCH_DATE) * 86400) + (tv_sec / 1000000.00);
> PQexecPrepared(connection,"addrow",1,(void*)values,lengths,formats,0);
>
> While the new code is something like:
>
> int64_t pg_timestamp;
> PQexec(connection,"prepare addrow (timestamp) as insert into mytable
> values ($1)");
> lengths[0] = sizeof(int64_t);
> formats[0] = 1;
> pg_timestamp = ((tv_sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) *
> 86400)) * (int64_t)1000000) + tv_usec;
> *(int64_t*)(values[0]) = bswap_64(pg_timestamp);
> PQexecPrepared(connection,"addrow",1,(void*)values,lengths,formats,0);
>
> I'll see about writing up a proper test case/schema. Looks like I'm
> probably most of the way there at this point, really. ;)
I wasn't aware you could throw binary values into the timestamp fields
like that. I thought you needed to use a C string for the value.
Does PREPARE bypass that for some reason?
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From | Date | Subject | |
---|---|---|---|
Next Message | Stephen Frost | 2004-05-20 15:53:03 | Re: Add error-checking to timestamp_recv |
Previous Message | Stephen Frost | 2004-05-20 15:43:14 | Re: Add error-checking to timestamp_recv |