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

Commit50626ef

Browse files
committed
Fix 3-parameter form of bit substring() to throw error for negative length,
as required by SQL standard.
1 parente4a6ebf commit50626ef

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.62 2010/01/0719:53:11 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.63 2010/01/0720:17:43 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -23,6 +23,9 @@
2323

2424
#defineHEXDIG(z) ((z)<10 ? ((z)+'0') : ((z)-10+'A'))
2525

26+
staticVarBit*bitsubstring(VarBit*arg,int32s,int32l,
27+
boollength_not_specified);
28+
2629

2730
/* common code for bittypmodin and varbittypmodin */
2831
staticint32
@@ -927,9 +930,23 @@ bitcat(PG_FUNCTION_ARGS)
927930
Datum
928931
bitsubstr(PG_FUNCTION_ARGS)
929932
{
930-
VarBit*arg=PG_GETARG_VARBIT_P(0);
931-
int32s=PG_GETARG_INT32(1);
932-
int32l=PG_GETARG_INT32(2);
933+
PG_RETURN_VARBIT_P(bitsubstring(PG_GETARG_VARBIT_P(0),
934+
PG_GETARG_INT32(1),
935+
PG_GETARG_INT32(2),
936+
false));
937+
}
938+
939+
Datum
940+
bitsubstr_no_len(PG_FUNCTION_ARGS)
941+
{
942+
PG_RETURN_VARBIT_P(bitsubstring(PG_GETARG_VARBIT_P(0),
943+
PG_GETARG_INT32(1),
944+
-1, true));
945+
}
946+
947+
staticVarBit*
948+
bitsubstring(VarBit*arg,int32s,int32l,boollength_not_specified)
949+
{
933950
VarBit*result;
934951
intbitlen,
935952
rbitlen,
@@ -947,14 +964,17 @@ bitsubstr(PG_FUNCTION_ARGS)
947964
bitlen=VARBITLEN(arg);
948965
s1=Max(s,1);
949966
/* If we do not have an upper bound, use end of string */
950-
if (l<0)
967+
if (length_not_specified)
951968
{
952969
e1=bitlen+1;
953970
}
954971
else
955972
{
956973
e=s+l;
957-
/* guard against overflow, even though we don't allow L<0 here */
974+
/*
975+
* A negative value for L is the only way for the end position
976+
* to be before the start. SQL99 says to throw an error.
977+
*/
958978
if (e<s)
959979
ereport(ERROR,
960980
(errcode(ERRCODE_SUBSTRING_ERROR),
@@ -1011,7 +1031,7 @@ bitsubstr(PG_FUNCTION_ARGS)
10111031
}
10121032
}
10131033

1014-
PG_RETURN_VARBIT_P(result);
1034+
returnresult;
10151035
}
10161036

10171037
/* bitlength, bitoctetlength

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.569 2010/01/06 05:18:18 momjian Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.570 2010/01/07 20:17:43 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201001061
56+
#defineCATALOG_VERSION_NO201001071
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.559 2010/01/05 01:06:56 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.560 2010/01/07 20:17:44 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.pl reads this file and generates .bki
@@ -2400,7 +2400,7 @@ DESCR("adjust varbit() to typmod length");
24002400

24012401
DATA(insertOID=1698 (positionPGNSPPGUID12100ffftfi2023"1560 1560"_null__null__null__null_bitposition_null__null__null_ ));
24022402
DESCR("return position of sub-bitstring");
2403-
DATA(insertOID=1699 (substringPGNSPPGUID14100ffftfi201560"1560 23"_null__null__null__null_"select pg_catalog.substring($1, $2, -1)"_null__null__null_ ));
2403+
DATA(insertOID=1699 (substringPGNSPPGUID12100ffftfi201560"1560 23"_null__null__null__null_bitsubstr_no_len_null__null__null_ ));
24042404
DESCR("return portion of bitstring");
24052405

24062406

‎src/include/utils/varbit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/utils/varbit.h,v 1.29 2010/01/02 16:58:10 momjian Exp $
11+
* $PostgreSQL: pgsql/src/include/utils/varbit.h,v 1.30 2010/01/07 20:17:44 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -88,6 +88,7 @@ extern Datum bitshiftleft(PG_FUNCTION_ARGS);
8888
externDatumbitshiftright(PG_FUNCTION_ARGS);
8989
externDatumbitcat(PG_FUNCTION_ARGS);
9090
externDatumbitsubstr(PG_FUNCTION_ARGS);
91+
externDatumbitsubstr_no_len(PG_FUNCTION_ARGS);
9192
externDatumbitlength(PG_FUNCTION_ARGS);
9293
externDatumbitoctetlength(PG_FUNCTION_ARGS);
9394
externDatumbitfromint4(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp