From: | Sam Mason <sam(at)samason(dot)me(dot)uk> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: INTERVAL data type and libpq - what format? |
Date: | 2009-05-19 10:09:32 |
Message-ID: | 20090519100932.GR22221@samason.me.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On Tue, May 19, 2009 at 10:08:37AM +0200, Sebastien FLAESCH wrote:
> I try to use the new 8.4 INTERVAL type with libpq, but get crazy with
> the input formatting rules...
I think you're giving the database conflicting instructions and it's
getting confused.
> fprintf(stdout,"++ Preparing INSERT ...\n");
> paramTypes[0] = 23; /* INT4 */
> paramTypes[1] = 1186; /* INTERVAL */
> paramTypes[2] = 1186; /* INTERVAL */
I don't really know 8.4, but I believe you're saying here that you
explicitly want the values to be of basic INTERVAL type here, i.e. not
INTERVAL DAY TO HOUR for parameter 3.
Thus when you do:
> paramValues[0] = "1";
> paramValues[1] = "-12345 years";
> paramValues[2] = " 123 11:00";
> r = PQexecPrepared(c, "s1", 3, paramValues, NULL, NULL, 0);
It's interpreting " 123 11:00" correctly as a basic INTERVAL value and
then casting it to your more constrained version as you're saving in the
table.
However, when you do:
> paramValues[0] = "2";
> paramValues[1] = "-12345";
> paramValues[2] = " 123 11";
> r = PQexecPrepared(c, "s1", 3, paramValues, NULL, NULL, 0);
You get an error because " 123 11" isn't a valid literal of an
(undecorated) INTERVAL type. I think PG may do the right thing if you
don't specify the types when preparing the query, but haven't tested.
--
Sam http://samason.me.uk/
From | Date | Subject | |
---|---|---|---|
Next Message | Raymond O'Donnell | 2009-05-19 10:10:34 | Re: Where is tsearch2.sql |
Previous Message | kelvin273 | 2009-05-19 10:05:02 | Re: my insertion script don't work |
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Riggs | 2009-05-19 11:32:13 | Multiple sorts in a query |
Previous Message | Richard Huxton | 2009-05-19 09:57:28 | Re: INTERVAL SECOND limited to 59 seconds? |