git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8d507c2)
Add text<->float8 and text<->float4 conversion functions.
1998年11月17日 14:36:51 +0000 (14:36 +0000)
1998年11月17日 14:36:51 +0000 (14:36 +0000)
This will fix the problem reported by Jose' Soares
when trying to cast a float to text.


diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index b1de92f643ee12fe6f108be49053d8160f02bda6..0bf5ebff472efa6cd8834ce48fd67b563c7347cd 100644 (file)
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -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
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 291ae18951b7b50f05b8a0ccdff08b4d5e8266c9..a53c2bc9789dfd4f78bb1bddff25103e66414122 100644 (file)
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -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ドル)" - ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 288c9db46e9c4a39cebbc451d7ad6a9bd024d1ce..f92cce669603ca6e718489fc397760ead85d6bbf 100644 (file)
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -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);
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /