From: | "David E(dot) Wheeler" <david(at)kineticode(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Typing Records |
Date: | 2010-08-24 03:33:47 |
Message-ID: | F197527F-D39E-4E31-9A1B-ED371DD22B2D@kineticode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hackers,
I've been trying to come up with a simpler way to iterate over a series of values in pgTAP tests than by creating a table, inserting rows, and then selecting from the table. The best I've come up with so far is:
CREATE TYPE vcmp AS ( lv semver, op text, rv semver);
SELECT cmp_ok(lv, op, rv) FROM unnest(ARRAY[
ROW('1.2.2', '=', '1.2.2')::vcmp,
ROW('1.2.23', '=', '1.2.23')::vcmp
]);
Not bad, but I was hoping that I could cast all the rows at once, without the type, like so:
SELECT cmp_ok(lv, op, rv) FROM unnest(ARRAY[
ROW('1.2.2', '=', '1.2.2'),
ROW('1.2.23', '=', '1.2.23')
]) AS f(lv semver, op text, rv semver);
But this gives me an error (9.0b4):
psql:t/types.pg:205: ERROR: function return row and query-specified return row do not match
DETAIL: Returned type unknown at ordinal position 1, but query expects semver.
Pity it doesn't default to casting to text there. So I tried to just cast the first row:
SELECT cmp_ok(lv, op, rv) FROM unnest(ARRAY[
ROW('1.2.2'::semver, '='::text, '1.2.2'::semver),
ROW('1.2.23', '=', '1.2.23')
]) AS f(lv semver, op text, rv semver);
That's even worse!
psql:t/types.pg:205: ERROR: invalid memory alloc request size 18446744071604011012
Wha??
That seems like a bug.
Aside from that, might there be another way to do this without an explicit composite type? Maybe with VALUES() or something?
Thanks,
David
From | Date | Subject | |
---|---|---|---|
Next Message | KaiGai Kohei | 2010-08-24 05:19:12 | Re: security hook on authorization |
Previous Message | Alvaro Herrera | 2010-08-24 01:08:21 | Re: Interruptible sleeps (was Re: CommitFest 2009-07: Yay, Kevin! Thanks, reviewers!) |