Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit643c7be

Browse files
author
Thomas G. Lockhart
committed
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.
1 parent8d507c2 commit643c7be

File tree

3 files changed

+130
-17
lines changed

3 files changed

+130
-17
lines changed

‎src/backend/utils/adt/float.c

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.33 1998/09/01 04:32:32 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.34 1998/11/17 14:36:44 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -926,6 +926,96 @@ i2tof(int16 num)
926926
}
927927

928928

929+
/*
930+
*float8_text- converts a float8 number to a text string
931+
*/
932+
text*
933+
float8_text(float64num)
934+
{
935+
text*result;
936+
intlen;
937+
char*str;
938+
939+
str=float8out(num);
940+
len= (strlen(str)+VARHDRSZ);
941+
942+
result=palloc(len);
943+
944+
VARSIZE(result)=len;
945+
memmove(VARDATA(result),str, (len-VARHDRSZ));
946+
947+
pfree(str);
948+
returnresult;
949+
}/* float8_text() */
950+
951+
952+
/*
953+
*text_float8- converts a text string to a float8 number
954+
*/
955+
float64
956+
text_float8(text*string)
957+
{
958+
float64result;
959+
intlen;
960+
char*str;
961+
962+
len= (VARSIZE(string)-VARHDRSZ);
963+
str=palloc(len+1);
964+
memmove(str,VARDATA(string),len);
965+
*(str+len)='\0';
966+
967+
result=float8in(str);
968+
pfree(str);
969+
970+
returnresult;
971+
}/* text_float8() */
972+
973+
974+
/*
975+
*float4_text- converts a float4 number to a text string
976+
*/
977+
text*
978+
float4_text(float32num)
979+
{
980+
text*result;
981+
intlen;
982+
char*str;
983+
984+
str=float4out(num);
985+
len= (strlen(str)+VARHDRSZ);
986+
987+
result=palloc(len);
988+
989+
VARSIZE(result)=len;
990+
memmove(VARDATA(result),str, (len-VARHDRSZ));
991+
992+
pfree(str);
993+
returnresult;
994+
}/* float4_text() */
995+
996+
997+
/*
998+
*text_float4- converts a text string to a float4 number
999+
*/
1000+
float32
1001+
text_float4(text*string)
1002+
{
1003+
float32result;
1004+
intlen;
1005+
char*str;
1006+
1007+
len= (VARSIZE(string)-VARHDRSZ);
1008+
str=palloc(len+1);
1009+
memmove(str,VARDATA(string),len);
1010+
*(str+len)='\0';
1011+
1012+
result=float4in(str);
1013+
pfree(str);
1014+
1015+
returnresult;
1016+
}/* text_float4() */
1017+
1018+
9291019
/*
9301020
*=======================
9311021
*RANDOM FLOAT8 OPERATORS

‎src/include/catalog/pg_proc.h

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_proc.h,v 1.83 1998/10/29 19:03:50 tgl Exp $
9+
* $Id: pg_proc.h,v 1.84 1998/11/17 14:36:51 thomas Exp $
1010
*
1111
* NOTES
1212
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1067,16 +1067,14 @@ DESCR("convert");
10671067
DATA(insertOID=819 (text_int4PGUID11ftf1f23"25"10000100foobar));
10681068
DESCR("convert");
10691069

1070-
DATA(insertOID=849 (textposPGUID11ftf2f23"25 25"100010foobar ));
1071-
DESCR("return position of substring");
1072-
DATA(insertOID=850 (textlikePGUID11ftf2f16"25 25"100010foobar ));
1073-
DESCR("matches LIKE expression");
1074-
DATA(insertOID=851 (textnlikePGUID11ftf2f16"25 25"100010foobar ));
1075-
DESCR("does not match LIKE expression");
1076-
DATA(insertOID=858 (namelikePGUID11ftf2f16"19 25"10000100foobar ));
1077-
DESCR("matches LIKE expression");
1078-
DATA(insertOID=859 (namenlikePGUID11ftf2f16"19 25"10000100foobar ));
1079-
DESCR("does not match LIKE expression");
1070+
DATA(insertOID=838 (text_float8PGUID11ftf1f701"25"10000100foobar));
1071+
DESCR("convert");
1072+
DATA(insertOID=839 (text_float4PGUID11ftf1f700"25"10000100foobar));
1073+
DESCR("convert");
1074+
DATA(insertOID=840 (float8_textPGUID11ftf1f25"701"10000100foobar));
1075+
DESCR("convert");
1076+
DATA(insertOID=841 (float4_textPGUID11ftf1f25"700"10000100foobar));
1077+
DESCR("convert");
10801078

10811079
DATA(insertOID=846 (cash_mul_flt4PGUID11ftf2f790"790 700"10000100foobar ));
10821080
DESCR("multiply");
@@ -1085,6 +1083,13 @@ DESCR("divide");
10851083
DATA(insertOID=848 (flt4_mul_cashPGUID11ftf2f790"700 790"10000100foobar ));
10861084
DESCR("multiply");
10871085

1086+
DATA(insertOID=849 (textposPGUID11ftf2f23"25 25"100010foobar ));
1087+
DESCR("return position of substring");
1088+
DATA(insertOID=850 (textlikePGUID11ftf2f16"25 25"100010foobar ));
1089+
DESCR("matches LIKE expression");
1090+
DATA(insertOID=851 (textnlikePGUID11ftf2f16"25 25"100010foobar ));
1091+
DESCR("does not match LIKE expression");
1092+
10881093
DATA(insertOID=852 (int48eqPGUID11ftf2f16"21 20"10000100foobar ));
10891094
DESCR("equal");
10901095
DATA(insertOID=853 (int48nePGUID11ftf2f16"21 20"10000100foobar ));
@@ -1098,6 +1103,11 @@ DESCR("less-than-or-equal");
10981103
DATA(insertOID=857 (int48gePGUID11ftf2f16"21 20"10000100foobar ));
10991104
DESCR("greater-than-or-equal");
11001105

1106+
DATA(insertOID=858 (namelikePGUID11ftf2f16"19 25"10000100foobar ));
1107+
DESCR("matches LIKE expression");
1108+
DATA(insertOID=859 (namenlikePGUID11ftf2f16"19 25"10000100foobar ));
1109+
DESCR("does not match LIKE expression");
1110+
11011111
DATA(insertOID=860 (char_bpcharPGUID11ftf1f1042"18"10000100foobar ));
11021112
DESCR("convert to bpchar");
11031113
DATA(insertOID=861 (bpchar_charPGUID11ftf1f18"1042"10000100foobar ));
@@ -1981,13 +1991,22 @@ DESCR("convert int8 to float8");
19811991
/* OIDS 1600 - 1699 */
19821992

19831993
DATA(insertOID=1600 (linePGUID14ftf2f628"600 600"10000100"select line_construct_pp($1, $2)"- ));
1984-
DESCR("");
1994+
DESCR("points to line");
19851995
DATA(insertOID=1601 (ishorizontalPGUID14ftf1f16"628"10000100"select line_horizontal($1)"- ));
1986-
DESCR("");
1996+
DESCR("is line horizontal?");
19871997
DATA(insertOID=1602 (isverticalPGUID14ftf1f16"628"10000100"select line_vertical($1)"- ));
1988-
DESCR("");
1998+
DESCR("is line vertical?");
19891999
DATA(insertOID=1603 (isparallelPGUID14ftf2f16"628 628"10000100"select line_parallel($1, $2)"- ));
1990-
DESCR("");
2000+
DESCR("are lines parallel?");
2001+
2002+
DATA(insertOID=1604 (float8PGUID14ftf1f701"25"10000100"select text_float8($1)"- ));
2003+
DESCR("convert");
2004+
DATA(insertOID=1605 (float4PGUID14ftf1f700"25"10000100"select text_float4($1)"- ));
2005+
DESCR("convert");
2006+
DATA(insertOID=1606 (textPGUID14ftf1f25"701"10000100"select float8_text($1)"- ));
2007+
DESCR("convert");
2008+
DATA(insertOID=1607 (textPGUID14ftf1f25"700"10000100"select float4_text($1)"- ));
2009+
DESCR("convert");
19912010

19922011
/* Oracle Compatibility Related Functions - By Edmund Mergl <E.Mergl@bawue.de> */
19932012
DATA(insertOID=868 (strposPGUID14ftf2f23"25 25"10000100"select textpos($1, $2)"- ));

‎src/include/utils/builtins.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: builtins.h,v 1.69 1998/10/29 18:07:09 momjian Exp $
9+
* $Id: builtins.h,v 1.70 1998/11/17 14:36:37 thomas Exp $
1010
*
1111
* NOTES
1212
* This should normally only be included by fmgr.h.
@@ -280,6 +280,10 @@ extern float32 i4tof(int32 num);
280280
externfloat32i2tof(int16num);
281281
externint32ftoi4(float32num);
282282
externint16ftoi2(float32num);
283+
externfloat64text_float8(text*str);
284+
externfloat32text_float4(text*str);
285+
externtext*float8_text(float64num);
286+
externtext*float4_text(float32num);
283287
externfloat64dround(float64arg1);
284288
externfloat64dtrunc(float64arg1);
285289
externfloat64dsqrt(float64arg1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp