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

Commitfef731d

Browse files
committed
The "Allow easy display of usernames in a group (pg_hba.conf uses groups
now)" item on the open items, and subsequent plpgsql function I sent in,made me realize it was too hard to get the upper and lower bound of anarray. The attached creates two functions that I think will be veryuseful when combined with the ability of plpgsql to return sets.array_lower(array, dim_num)- and -array_upper(array, dim_num)They return the value (as an int) of the upper and lower bound of therequested dim in the provided array.Joe Conway
1 parent7eb2b4b commitfef731d

File tree

4 files changed

+70
-5
lines changed

4 files changed

+70
-5
lines changed

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

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.81 2002/09/18 21:35:22 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.82 2002/11/08 17:27:02 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -866,6 +866,65 @@ array_dims(PG_FUNCTION_ARGS)
866866
PG_RETURN_TEXT_P(result);
867867
}
868868

869+
/*-----------------------------------------------------------------------------
870+
* array_lower :
871+
*returns the lower dimension, of the DIM requested, for
872+
*the array pointed to by "v", as an int4
873+
*----------------------------------------------------------------------------
874+
*/
875+
Datum
876+
array_lower(PG_FUNCTION_ARGS)
877+
{
878+
ArrayType*v=PG_GETARG_ARRAYTYPE_P(0);
879+
intreqdim=PG_GETARG_INT32(1);
880+
int*lb;
881+
intresult;
882+
883+
/* Sanity check: does it look like an array at all? */
884+
if (ARR_NDIM(v) <=0||ARR_NDIM(v)>MAXDIM)
885+
PG_RETURN_NULL();
886+
887+
/* Sanity check: was the requested dim valid */
888+
if (reqdim <=0||reqdim>ARR_NDIM(v))
889+
PG_RETURN_NULL();
890+
891+
lb=ARR_LBOUND(v);
892+
result=lb[reqdim-1];
893+
894+
PG_RETURN_INT32(result);
895+
}
896+
897+
/*-----------------------------------------------------------------------------
898+
* array_upper :
899+
*returns the upper dimension, of the DIM requested, for
900+
*the array pointed to by "v", as an int4
901+
*----------------------------------------------------------------------------
902+
*/
903+
Datum
904+
array_upper(PG_FUNCTION_ARGS)
905+
{
906+
ArrayType*v=PG_GETARG_ARRAYTYPE_P(0);
907+
intreqdim=PG_GETARG_INT32(1);
908+
int*dimv,
909+
*lb;
910+
intresult;
911+
912+
/* Sanity check: does it look like an array at all? */
913+
if (ARR_NDIM(v) <=0||ARR_NDIM(v)>MAXDIM)
914+
PG_RETURN_NULL();
915+
916+
/* Sanity check: was the requested dim valid */
917+
if (reqdim <=0||reqdim>ARR_NDIM(v))
918+
PG_RETURN_NULL();
919+
920+
lb=ARR_LBOUND(v);
921+
dimv=ARR_DIMS(v);
922+
923+
result=dimv[reqdim-1]+lb[reqdim-1]-1;
924+
925+
PG_RETURN_INT32(result);
926+
}
927+
869928
/*---------------------------------------------------------------------------
870929
* array_ref :
871930
* This routine takes an array pointer and an index array and returns

‎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-2002, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $Id: catversion.h,v 1.163 2002/11/02 18:41:22 tgl Exp $
40+
* $Id: catversion.h,v 1.164 2002/11/08 17:27:03 momjian Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200211021
56+
#defineCATALOG_VERSION_NO200211081
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.275 2002/11/02 18:41:22 tgl Exp $
10+
* $Id: pg_proc.h,v 1.276 2002/11/08 17:27:03 momjian Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1000,6 +1000,10 @@ DATA(insert OID = 750 ( array_in PGNSP PGUID 12 f f t f s 3 2277 "2275 26 2
10001000
DESCR("array");
10011001
DATA(insertOID=751 (array_outPGNSPPGUID12fftfs12275"2277"array_out-_null_ ));
10021002
DESCR("array");
1003+
DATA(insertOID=2091 (array_lowerPGNSPPGUID12fftfi223"2277 23"array_lower-_null_ ));
1004+
DESCR("array lower dimension");
1005+
DATA(insertOID=2092 (array_upperPGNSPPGUID12fftfi223"2277 23"array_upper-_null_ ));
1006+
DESCR("array upper dimension");
10031007

10041008
DATA(insertOID=760 (smgrinPGNSPPGUID12fftfs1210"2275"smgrin-_null_ ));
10051009
DESCR("storage manager(internal)");

‎src/include/utils/array.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $Id: array.h,v 1.35 2002/09/18 21:35:24 tgl Exp $
13+
* $Id: array.h,v 1.36 2002/11/08 17:27:03 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -85,6 +85,8 @@ extern Datum array_out(PG_FUNCTION_ARGS);
8585
externDatumarray_length_coerce(PG_FUNCTION_ARGS);
8686
externDatumarray_eq(PG_FUNCTION_ARGS);
8787
externDatumarray_dims(PG_FUNCTION_ARGS);
88+
externDatumarray_lower(PG_FUNCTION_ARGS);
89+
externDatumarray_upper(PG_FUNCTION_ARGS);
8890

8991
externDatumarray_ref(ArrayType*array,intnSubscripts,int*indx,
9092
intarraylen,intelmlen,boolelmbyval,charelmalign,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp