Add text<->float8 and text<->float4 conversion functions.

This will fix the problem reported by Jose' Soares
 when trying to cast a float to text.
This commit is contained in:
Thomas G. Lockhart 1998-11-17 14:36:51 +00:00
parent 8d507c204b
commit 643c7beddf
3 changed files with 130 additions and 17 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.33 1998/09/01 04:32:32 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.34 1998/11/17 14:36:44 thomas Exp $
*
*-------------------------------------------------------------------------
*/
@ -926,6 +926,96 @@ i2tof(int16 num)
}
/*
* float8_text - converts a float8 number to a text string
*/
text *
float8_text(float64 num)
{
text *result;
int len;
char *str;
str = float8out(num);
len = (strlen(str)+VARHDRSZ);
result = palloc(len);
VARSIZE(result) = len;
memmove(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
return result;
} /* float8_text() */
/*
* text_float8 - converts a text string to a float8 number
*/
float64
text_float8(text *string)
{
float64 result;
int len;
char *str;
len = (VARSIZE(string) - VARHDRSZ);
str = palloc(len + 1);
memmove(str, VARDATA(string), len);
*(str + len) = '\0';
result = float8in(str);
pfree(str);
return result;
} /* text_float8() */
/*
* float4_text - converts a float4 number to a text string
*/
text *
float4_text(float32 num)
{
text *result;
int len;
char *str;
str = float4out(num);
len = (strlen(str)+VARHDRSZ);
result = palloc(len);
VARSIZE(result) = len;
memmove(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
return result;
} /* float4_text() */
/*
* text_float4 - converts a text string to a float4 number
*/
float32
text_float4(text *string)
{
float32 result;
int len;
char *str;
len = (VARSIZE(string) - VARHDRSZ);
str = palloc(len + 1);
memmove(str, VARDATA(string), len);
*(str + len) = '\0';
result = float4in(str);
pfree(str);
return result;
} /* text_float4() */
/*
* =======================
* RANDOM FLOAT8 OPERATORS

View File

@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_proc.h,v 1.83 1998/10/29 19:03:50 tgl Exp $
* $Id: pg_proc.h,v 1.84 1998/11/17 14:36:51 thomas Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
@ -1067,16 +1067,14 @@ DESCR("convert");
DATA(insert OID = 819 ( text_int4 PGUID 11 f t f 1 f 23 "25" 100 0 0 100 foo bar));
DESCR("convert");
DATA(insert OID = 849 ( textpos PGUID 11 f t f 2 f 23 "25 25" 100 0 1 0 foo bar ));
DESCR("return position of substring");
DATA(insert OID = 850 ( textlike PGUID 11 f t f 2 f 16 "25 25" 100 0 1 0 foo bar ));
DESCR("matches LIKE expression");
DATA(insert OID = 851 ( textnlike PGUID 11 f t f 2 f 16 "25 25" 100 0 1 0 foo bar ));
DESCR("does not match LIKE expression");
DATA(insert OID = 858 ( namelike PGUID 11 f t f 2 f 16 "19 25" 100 0 0 100 foo bar ));
DESCR("matches LIKE expression");
DATA(insert OID = 859 ( namenlike PGUID 11 f t f 2 f 16 "19 25" 100 0 0 100 foo bar ));
DESCR("does not match LIKE expression");
DATA(insert OID = 838 ( text_float8 PGUID 11 f t f 1 f 701 "25" 100 0 0 100 foo bar));
DESCR("convert");
DATA(insert OID = 839 ( text_float4 PGUID 11 f t f 1 f 700 "25" 100 0 0 100 foo bar));
DESCR("convert");
DATA(insert OID = 840 ( float8_text PGUID 11 f t f 1 f 25 "701" 100 0 0 100 foo bar));
DESCR("convert");
DATA(insert OID = 841 ( float4_text PGUID 11 f t f 1 f 25 "700" 100 0 0 100 foo bar));
DESCR("convert");
DATA(insert OID = 846 ( cash_mul_flt4 PGUID 11 f t f 2 f 790 "790 700" 100 0 0 100 foo bar ));
DESCR("multiply");
@ -1085,6 +1083,13 @@ DESCR("divide");
DATA(insert OID = 848 ( flt4_mul_cash PGUID 11 f t f 2 f 790 "700 790" 100 0 0 100 foo bar ));
DESCR("multiply");
DATA(insert OID = 849 ( textpos PGUID 11 f t f 2 f 23 "25 25" 100 0 1 0 foo bar ));
DESCR("return position of substring");
DATA(insert OID = 850 ( textlike PGUID 11 f t f 2 f 16 "25 25" 100 0 1 0 foo bar ));
DESCR("matches LIKE expression");
DATA(insert OID = 851 ( textnlike PGUID 11 f t f 2 f 16 "25 25" 100 0 1 0 foo bar ));
DESCR("does not match LIKE expression");
DATA(insert OID = 852 ( int48eq PGUID 11 f t f 2 f 16 "21 20" 100 0 0 100 foo bar ));
DESCR("equal");
DATA(insert OID = 853 ( int48ne PGUID 11 f t f 2 f 16 "21 20" 100 0 0 100 foo bar ));
@ -1098,6 +1103,11 @@ DESCR("less-than-or-equal");
DATA(insert OID = 857 ( int48ge PGUID 11 f t f 2 f 16 "21 20" 100 0 0 100 foo bar ));
DESCR("greater-than-or-equal");
DATA(insert OID = 858 ( namelike PGUID 11 f t f 2 f 16 "19 25" 100 0 0 100 foo bar ));
DESCR("matches LIKE expression");
DATA(insert OID = 859 ( namenlike PGUID 11 f t f 2 f 16 "19 25" 100 0 0 100 foo bar ));
DESCR("does not match LIKE expression");
DATA(insert OID = 860 ( char_bpchar PGUID 11 f t f 1 f 1042 "18" 100 0 0 100 foo bar ));
DESCR("convert to bpchar");
DATA(insert OID = 861 ( bpchar_char PGUID 11 f t f 1 f 18 "1042" 100 0 0 100 foo bar ));
@ -1981,13 +1991,22 @@ DESCR("convert int8 to float8");
/* OIDS 1600 - 1699 */
DATA(insert OID = 1600 ( line PGUID 14 f t f 2 f 628 "600 600" 100 0 0 100 "select line_construct_pp($1, $2)" - ));
DESCR("");
DESCR("points to line");
DATA(insert OID = 1601 ( ishorizontal PGUID 14 f t f 1 f 16 "628" 100 0 0 100 "select line_horizontal($1)" - ));
DESCR("");
DESCR("is line horizontal?");
DATA(insert OID = 1602 ( isvertical PGUID 14 f t f 1 f 16 "628" 100 0 0 100 "select line_vertical($1)" - ));
DESCR("");
DESCR("is line vertical?");
DATA(insert OID = 1603 ( isparallel PGUID 14 f t f 2 f 16 "628 628" 100 0 0 100 "select line_parallel($1, $2)" - ));
DESCR("");
DESCR("are lines parallel?");
DATA(insert OID = 1604 ( float8 PGUID 14 f t f 1 f 701 "25" 100 0 0 100 "select text_float8($1)" - ));
DESCR("convert");
DATA(insert OID = 1605 ( float4 PGUID 14 f t f 1 f 700 "25" 100 0 0 100 "select text_float4($1)" - ));
DESCR("convert");
DATA(insert OID = 1606 ( text PGUID 14 f t f 1 f 25 "701" 100 0 0 100 "select float8_text($1)" - ));
DESCR("convert");
DATA(insert OID = 1607 ( text PGUID 14 f t f 1 f 25 "700" 100 0 0 100 "select float4_text($1)" - ));
DESCR("convert");
/* Oracle Compatibility Related Functions - By Edmund Mergl <E.Mergl@bawue.de> */
DATA(insert OID = 868 ( strpos PGUID 14 f t f 2 f 23 "25 25" 100 0 0 100 "select textpos($1, $2)" - ));

View File

@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: builtins.h,v 1.69 1998/10/29 18:07:09 momjian Exp $
* $Id: builtins.h,v 1.70 1998/11/17 14:36:37 thomas Exp $
*
* NOTES
* This should normally only be included by fmgr.h.
@ -280,6 +280,10 @@ extern float32 i4tof(int32 num);
extern float32 i2tof(int16 num);
extern int32 ftoi4(float32 num);
extern int16 ftoi2(float32 num);
extern float64 text_float8(text *str);
extern float32 text_float4(text *str);
extern text *float8_text(float64 num);
extern text *float4_text(float32 num);
extern float64 dround(float64 arg1);
extern float64 dtrunc(float64 arg1);
extern float64 dsqrt(float64 arg1);