[HACKERS] more problems with the money type

2007-08-20 Thread Merlin Moncure
while playing with the binary transport of the money type we found
another bug.  The following code segfaults the server on 8.3cvs:

select '3'::money * 2;

this was an accidental discovery by us but is the second serious bug
we found with the money type without looking very hard...probably
stemming from the bump to 64 bit in jan 07 (8.2 does not have this
behavior).

aside: since the money type was deprecated, why was it bumped to 64 bits?

merlin

---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


Re: [HACKERS] more problems with the money type

2007-08-20 Thread D'Arcy J.M. Cain
On Mon, 20 Aug 2007 17:32:42 -0400
Merlin Moncure [EMAIL PROTECTED] wrote:
 while playing with the binary transport of the money type we found
 another bug.  The following code segfaults the server on 8.3cvs:
 
 select '3'::money * 2;

What does SELECT 2 * '3'::money; do?  If that works try changing 64
to 32 in the function cash_mul_int4.  Let me know and I will commit
the fix as soon as I get CVS access again.

 aside: since the money type was deprecated, why was it bumped to 64 bits?

See the archives.

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
   choose an index scan if your joining column's datatypes do not
   match


Re: [HACKERS] more problems with the money type

2007-08-20 Thread Andrew Chernow

 What does SELECT 2 * '3'::money; do?
That works.

try changing 64 to 32 in the function cash_mul_int4
That also worked.

Datum
cash_mul_int4(PG_FUNCTION_ARGS)
{
Cashc = PG_GETARG_CASH(0);
/*int64 i = PG_GETARG_INT64(1);*/
int32   i = PG_GETARG_INT32(1);
Cashresult;

result = c * i;
PG_RETURN_CASH(result);
}

See submitted patch that fixes cash_send and cash_recv as well.
Patch: http://archives.postgresql.org/pgsql-patches/2007-08/msg00117.php

Andrew


D'Arcy J.M. Cain wrote:

On Mon, 20 Aug 2007 17:32:42 -0400
Merlin Moncure [EMAIL PROTECTED] wrote:

while playing with the binary transport of the money type we found
another bug.  The following code segfaults the server on 8.3cvs:

select '3'::money * 2;


What does SELECT 2 * '3'::money; do?  If that works try changing 64
to 32 in the function cash_mul_int4.  Let me know and I will commit
the fix as soon as I get CVS access again.


aside: since the money type was deprecated, why was it bumped to 64 bits?


See the archives.



---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [HACKERS] more problems with the money type

2007-08-20 Thread Andrew Chernow
Division segfaults server as well - SELECT '3'::money / 2 - for the same reason 
multiplication did.


/* cash_div_int4()
 * Divide cash by 4-byte integer.
 *
 */
Datum
cash_div_int4(PG_FUNCTION_ARGS)
{
Cashc = PG_GETARG_CASH(0);
int64   i = PG_GETARG_INT64(1);
Cashresult;

if (i == 0)
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
 errmsg(division by zero)));

result = rint(c / i);

PG_RETURN_CASH(result);
}

Should be int32 i = PG_GETARG_INT32(1); just like cash_mul_int4().

Andrew



Andrew Chernow wrote:

  What does SELECT 2 * '3'::money; do?
That works.

 try changing 64 to 32 in the function cash_mul_int4
That also worked.

Datum
cash_mul_int4(PG_FUNCTION_ARGS)
{
Cashc = PG_GETARG_CASH(0);
/*int64i = PG_GETARG_INT64(1);*/
int32   i = PG_GETARG_INT32(1);
Cashresult;

result = c * i;
PG_RETURN_CASH(result);
}

See submitted patch that fixes cash_send and cash_recv as well.
Patch: http://archives.postgresql.org/pgsql-patches/2007-08/msg00117.php

Andrew


D'Arcy J.M. Cain wrote:

On Mon, 20 Aug 2007 17:32:42 -0400
Merlin Moncure [EMAIL PROTECTED] wrote:

while playing with the binary transport of the money type we found
another bug.  The following code segfaults the server on 8.3cvs:

select '3'::money * 2;


What does SELECT 2 * '3'::money; do?  If that works try changing 64
to 32 in the function cash_mul_int4.  Let me know and I will commit
the fix as soon as I get CVS access again.

aside: since the money type was deprecated, why was it bumped to 64 
bits?


See the archives.



---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly




---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match


Re: [HACKERS] more problems with the money type

2007-08-20 Thread D'Arcy J.M. Cain
On Mon, 20 Aug 2007 20:00:47 -0400
Andrew Chernow [EMAIL PROTECTED] wrote:
   What does SELECT 2 * '3'::money; do?
 That works.
 
  try changing 64 to 32 in the function cash_mul_int4
 That also worked.
 
 See submitted patch that fixes cash_send and cash_recv as well.
 Patch: http://archives.postgresql.org/pgsql-patches/2007-08/msg00117.php

I am still waiting for Magnus to restore my CVS access following the
move.  Can someone else commit these fixes?

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [HACKERS] more problems with the money type

2007-08-20 Thread Tom Lane
Andrew Chernow [EMAIL PROTECTED] writes:
 Division segfaults server as well - SELECT '3'::money / 2 - for the same 
 reason 
 multiplication did.

Yup.  A quick scan doesn't show any other mistaken int32-int64
replacements in the file, but maybe someone wants to look closer?

Patch applied.

regards, tom lane

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings