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

Commitea01a45

Browse files
author
Thomas G. Lockhart
committed
Implement SQL99 OVERLAY(). Allows substitution of a substring in a string.
Implement SQL99 SIMILAR TO as a synonym for our existing operator "~".Implement SQL99 regular expression SUBSTRING(string FROM pat FOR escape). Extend the definition to make the FOR clause optional. Define textregexsubstr() to actually implement this feature.Update the regression test to include these new string features. All tests pass.Rename the regular expression support routines from "pg95_xxx" to "pg_xxx".Define CREATE CHARACTER SET in the parser per SQL99. No implementation yet.
1 parent090dd22 commitea01a45

File tree

16 files changed

+519
-256
lines changed

16 files changed

+519
-256
lines changed

‎doc/src/sgml/ref/set.sgml

Lines changed: 186 additions & 192 deletions
Large diffs are not rendered by default.

‎src/backend/parser/gram.y

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.320 2002/06/1113:40:50 wieck Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.321 2002/06/1115:41:37 thomas Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -227,10 +227,10 @@ static void doNegateFloat(Value *v);
227227
%type<node>join_outer,join_qual
228228
%type<jtype>join_type
229229

230-
%type<list>extract_list,position_list
230+
%type<list>extract_list,overlay_list,position_list
231231
%type<list>substr_list,trim_list
232232
%type<ival>opt_interval
233-
%type<node>substr_from,substr_for
233+
%type<node>overlay_placing,substr_from,substr_for
234234

235235
%type<boolean>opt_binary,opt_using,opt_instead,opt_cursor
236236
%type<boolean>opt_with_copy,index_opt_unique,opt_verbose,opt_full
@@ -336,7 +336,7 @@ static void doNegateFloat(Value *v);
336336
FALSE_P, FETCH, FLOAT_P, FOR, FORCE, FOREIGN, FORWARD, FREEZE, FROM,
337337
FULL, FUNCTION,
338338

339-
GLOBAL, GRANT, GROUP_P,
339+
GET,GLOBAL, GRANT, GROUP_P,
340340
HANDLER, HAVING, HOUR_P,
341341

342342
ILIKE, IMMEDIATE, IMMUTABLE, IMPLICIT, IN_P, INCREMENT, INDEX, INHERITS,
@@ -356,16 +356,16 @@ static void doNegateFloat(Value *v);
356356
NUMERIC,
357357

358358
OF, OFF, OFFSET, OIDS, OLD, ON, ONLY, OPERATOR, OPTION, OR, ORDER,
359-
OUT_P, OUTER_P, OVERLAPS, OWNER,
359+
OUT_P, OUTER_P, OVERLAPS,OVERLAY,OWNER,
360360

361-
PARTIAL, PASSWORD, PATH_P, PENDANT, POSITION, PRECISION, PRIMARY,
361+
PARTIAL, PASSWORD, PATH_P, PENDANT,PLACING,POSITION, PRECISION, PRIMARY,
362362
PRIOR, PRIVILEGES, PROCEDURE, PROCEDURAL,
363363

364364
READ, REAL, REFERENCES, REINDEX, RELATIVE, RENAME, REPLACE, RESET,
365365
RESTRICT, RETURNS, REVOKE, RIGHT, ROLLBACK, ROW, RULE,
366366

367367
SCHEMA, SCROLL, SECOND_P, SECURITY, SELECT, SEQUENCE, SERIALIZABLE,
368-
SESSION, SESSION_USER, SET, SETOF, SHARE, SHOW, SMALLINT, SOME,
368+
SESSION, SESSION_USER, SET, SETOF, SHARE, SHOW,SIMILAR,SMALLINT, SOME,
369369
STABLE, START, STATEMENT, STATISTICS, STDIN, STDOUT, STORAGE, STRICT,
370370
SUBSTRING, SYSID,
371371

@@ -402,7 +402,7 @@ static void doNegateFloat(Value *v);
402402
%rightNOT
403403
%right'='
404404
%nonassoc'<''>'
405-
%nonassocLIKEILIKE
405+
%nonassocLIKEILIKESIMILAR
406406
%nonassocESCAPE
407407
%nonassocOVERLAPS
408408
%nonassocBETWEEN
@@ -420,6 +420,7 @@ static void doNegateFloat(Value *v);
420420
%rightUMINUS
421421
%left'['']'
422422
%left'('')'
423+
%leftCOLLATE
423424
%leftTYPECAST
424425
%left'.'
425426
%%
@@ -2139,6 +2140,14 @@ DefineStmt: CREATE AGGREGATE func_name definition
21392140
n->definition =$4;
21402141
$$ = (Node *)n;
21412142
}
2143+
|CREATECHARACTERSETopt_asany_nameGETdefinitionopt_collate
2144+
{
2145+
DefineStmt *n = makeNode(DefineStmt);
2146+
n->defType = CHARACTER;
2147+
n->defnames =$5;
2148+
n->definition =$7;
2149+
$$ = (Node *)n;
2150+
}
21422151
;
21432152

21442153
definition:'('def_list')'{$$ =$2; }
@@ -4978,9 +4987,18 @@ qual_all_Op: all_Op
49784987
* it's factored out just to eliminate redundant coding.
49794988
*/
49804989
a_expr:c_expr
4981-
{$$ =$1;}
4990+
{$$ =$1; }
49824991
|a_exprTYPECASTTypename
49834992
{$$ = makeTypeCast($1,$3); }
4993+
|a_exprCOLLATEColId
4994+
{
4995+
FuncCall *n = makeNode(FuncCall);
4996+
n->funcname = SystemFuncName($3);
4997+
n->args = makeList1($1);
4998+
n->agg_star =FALSE;
4999+
n->agg_distinct =FALSE;
5000+
$$ = (Node *) n;
5001+
}
49845002
|a_exprATTIMEZONEc_expr
49855003
{
49865004
FuncCall *n = makeNode(FuncCall);
@@ -5088,6 +5106,30 @@ a_expr: c_expr
50885106
n->agg_distinct =FALSE;
50895107
$$ = (Node *) makeSimpleA_Expr(OP,"!~~*",$1, (Node *) n);
50905108
}
5109+
5110+
|a_exprSIMILARTOa_expr%precSIMILAR
5111+
{$$ = (Node *) makeSimpleA_Expr(OP,"~",$1,$4); }
5112+
|a_exprSIMILARTOa_exprESCAPEa_expr
5113+
{
5114+
FuncCall *n = makeNode(FuncCall);
5115+
n->funcname = SystemFuncName("like_escape");
5116+
n->args = makeList2($4,$6);
5117+
n->agg_star =FALSE;
5118+
n->agg_distinct =FALSE;
5119+
$$ = (Node *) makeSimpleA_Expr(OP,"~",$1, (Node *) n);
5120+
}
5121+
|a_exprNOTSIMILARTOa_expr%precSIMILAR
5122+
{$$ = (Node *) makeSimpleA_Expr(OP,"!~",$1,$5); }
5123+
|a_exprNOTSIMILARTOa_exprESCAPEa_expr
5124+
{
5125+
FuncCall *n = makeNode(FuncCall);
5126+
n->funcname = SystemFuncName("like_escape");
5127+
n->args = makeList2($5,$7);
5128+
n->agg_star =FALSE;
5129+
n->agg_distinct =FALSE;
5130+
$$ = (Node *) makeSimpleA_Expr(OP,"!~",$1, (Node *) n);
5131+
}
5132+
50915133
/* NullTest clause
50925134
* Define SQL92-style Null test clause.
50935135
* Allow two forms described in the standard:
@@ -5568,6 +5610,20 @@ c_expr: columnref
55685610
n->agg_distinct =FALSE;
55695611
$$ = (Node *)n;
55705612
}
5613+
|OVERLAY'('overlay_list')'
5614+
{
5615+
/* overlay(A PLACING B FROM C FOR D) is converted to
5616+
* substring(A, 1, C-1) || B || substring(A, C+1, C+D)
5617+
* overlay(A PLACING B FROM C) is converted to
5618+
* substring(A, 1, C-1) || B || substring(A, C+1, C+char_length(B))
5619+
*/
5620+
FuncCall *n = makeNode(FuncCall);
5621+
n->funcname = SystemFuncName("overlay");
5622+
n->args =$3;
5623+
n->agg_star =FALSE;
5624+
n->agg_distinct =FALSE;
5625+
$$ = (Node *)n;
5626+
}
55715627
|POSITION'('position_list')'
55725628
{
55735629
/* position(A in B) is converted to position(B, A)*/
@@ -5706,6 +5762,25 @@ extract_arg: IDENT{ $$ = $1; }
57065762
|SCONST{$$ =$1; }
57075763
;
57085764

5765+
/* OVERLAY() arguments
5766+
* SQL99 defines the OVERLAY() function:
5767+
* o overlay(text placing text from int for int)
5768+
* o overlay(text placing text from int)
5769+
*/
5770+
overlay_list:a_exproverlay_placingsubstr_fromsubstr_for
5771+
{
5772+
$$ = makeList4($1,$2,$3,$4);
5773+
}
5774+
|a_exproverlay_placingsubstr_from
5775+
{
5776+
$$ = makeList3($1,$2,$3);
5777+
}
5778+
;
5779+
5780+
overlay_placing:PLACINGa_expr
5781+
{$$ =$2; }
5782+
;
5783+
57095784
/* position_list uses b_expr not a_expr to avoid conflict with general IN*/
57105785

57115786
position_list:b_exprIN_Pb_expr
@@ -6259,6 +6334,7 @@ unreserved_keyword:
62596334
| FORCE
62606335
| FORWARD
62616336
| FUNCTION
6337+
| GET
62626338
| GLOBAL
62636339
| HANDLER
62646340
| HOUR_P
@@ -6404,6 +6480,7 @@ col_name_keyword:
64046480
| NONE
64056481
| NULLIF
64066482
| NUMERIC
6483+
| OVERLAY
64076484
| POSITION
64086485
| REAL
64096486
| SETOF
@@ -6423,7 +6500,7 @@ col_name_keyword:
64236500
*
64246501
* Do not include POSITION, SUBSTRING, etc here since they have explicit
64256502
* productions in a_expr to support the goofy SQL9x argument syntax.
6426-
*- thomas 2000-11-28
6503+
* - thomas 2000-11-28
64276504
*/
64286505
func_name_keyword:
64296506
AUTHORIZATION
@@ -6445,6 +6522,7 @@ func_name_keyword:
64456522
| OUTER_P
64466523
| OVERLAPS
64476524
| RIGHT
6525+
| SIMILAR
64486526
| VERBOSE
64496527
;
64506528

‎src/backend/parser/keywords.c

Lines changed: 5 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/parser/keywords.c,v 1.112 2002/06/1113:40:51 wieck Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.113 2002/06/1115:41:37 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -129,6 +129,7 @@ static const ScanKeyword ScanKeywords[] = {
129129
{"from",FROM},
130130
{"full",FULL},
131131
{"function",FUNCTION},
132+
{"get",GET},
132133
{"global",GLOBAL},
133134
{"grant",GRANT},
134135
{"group",GROUP_P},
@@ -211,11 +212,13 @@ static const ScanKeyword ScanKeywords[] = {
211212
{"out",OUT_P},
212213
{"outer",OUTER_P},
213214
{"overlaps",OVERLAPS},
215+
{"overlay",OVERLAY},
214216
{"owner",OWNER},
215217
{"partial",PARTIAL},
216218
{"password",PASSWORD},
217219
{"path",PATH_P},
218220
{"pendant",PENDANT},
221+
{"placing",PLACING},
219222
{"position",POSITION},
220223
{"precision",PRECISION},
221224
{"primary",PRIMARY},
@@ -251,6 +254,7 @@ static const ScanKeyword ScanKeywords[] = {
251254
{"setof",SETOF},
252255
{"share",SHARE},
253256
{"show",SHOW},
257+
{"similar",SIMILAR},
254258
{"smallint",SMALLINT},
255259
{"some",SOME},
256260
{"stable",STABLE},

‎src/backend/parser/scan.l

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.94 2002/05/02 18:44:10 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.95 2002/06/11 15:41:37 thomas Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -92,25 +92,25 @@ unsigned char unescape_single_char(unsigned char c);
9292
* We use exclusive states for quoted strings, extended comments,
9393
* and to eliminate parsing troubles for numeric strings.
9494
* Exclusive states:
95-
* <xbit> bit string literal
95+
* <xb> bit string literal
9696
* <xc> extended C-style comments - thomas 1997-07-12
9797
* <xd> delimited identifiers (double-quoted identifiers) - thomas 1997-10-27
9898
* <xh> hexadecimal numeric string - thomas 1997-11-16
9999
* <xq> quoted strings - thomas 1997-07-30
100100
*/
101101

102-
%xxbit
102+
%xxb
103103
%xxc
104104
%xxd
105105
%xxh
106106
%xxq
107107

108108
/* Bit string
109109
*/
110-
xbitstart[bB]{quote}
111-
xbitstop{quote}
112-
xbitinside[^']*
113-
xbitcat{quote}{whitespace_with_newline}{quote}
110+
xbstart[bB]{quote}
111+
xbstop{quote}
112+
xbinside[^']*
113+
xbcat{quote}{whitespace_with_newline}{quote}
114114

115115
/* Hexadecimal number
116116
*/
@@ -285,28 +285,28 @@ other.
285285

286286
<xc><<EOF>>{yyerror("unterminated /* comment"); }
287287

288-
{xbitstart}{
288+
{xbstart}{
289289
token_start = yytext;
290-
BEGIN(xbit);
290+
BEGIN(xb);
291291
startlit();
292292
addlitchar('b');
293293
}
294-
<xbit>{xbitstop}{
294+
<xb>{xbstop}{
295295
BEGIN(INITIAL);
296296
if (literalbuf[strspn(literalbuf +1,"01") +1] !='\0')
297297
yyerror("invalid bit string input");
298298
yylval.str =litbufdup();
299299
return BITCONST;
300300
}
301301
<xh>{xhinside}|
302-
<xbit>{xbitinside}{
302+
<xb>{xbinside}{
303303
addlit(yytext, yyleng);
304304
}
305305
<xh>{xhcat}|
306-
<xbit>{xbitcat}{
306+
<xb>{xbcat}{
307307
/* ignore */
308308
}
309-
<xbit><<EOF>>{yyerror("unterminated bit string literal"); }
309+
<xb><<EOF>>{yyerror("unterminated bit string literal"); }
310310

311311
{xhstart}{
312312
token_start = yytext;

‎src/backend/regex/regcomp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,10 @@ static intnever = 0;/* for use in asserts; shuts lint up */
174174

175175
/*
176176
* regcomp - interface for parser and compilation
177+
* returns 0 success, otherwise REG_something
177178
*/
178-
int/* 0 success, otherwise REG_something */
179-
pg95_regcomp(regex_t*preg,constchar*pattern,intcflags)
179+
int
180+
pg_regcomp(regex_t*preg,constchar*pattern,intcflags)
180181
{
181182
structparsepa;
182183
structre_guts*g;
@@ -224,7 +225,6 @@ pg95_regcomp(regex_t *preg, const char *pattern, int cflags)
224225
(void)pg_mb2wchar((unsignedchar*)pattern,wcp);
225226
len=pg_wchar_strlen(wcp);
226227
#else
227-
228228
len=strlen((char*)pattern);
229229
#endif
230230
}
@@ -305,7 +305,7 @@ pg95_regcomp(regex_t *preg, const char *pattern, int cflags)
305305

306306
/* win or lose, we're done */
307307
if (p->error!=0)/* lose */
308-
pg95_regfree(preg);
308+
pg_regfree(preg);
309309
returnp->error;
310310
}
311311

‎src/backend/regex/regerror.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ static struct rerr
117117
*/
118118
/* ARGSUSED */
119119
size_t
120-
pg95_regerror(interrcode,constregex_t*preg,
121-
char*errbuf,size_terrbuf_size)
120+
pg_regerror(interrcode,constregex_t*preg,
121+
char*errbuf,size_terrbuf_size)
122122
{
123123
structrerr*r;
124124
size_tlen;

‎src/backend/regex/regexec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ do { \
149149
* when choosing which matcher to call.
150150
*/
151151
int/* 0 success, REG_NOMATCH failure */
152-
pg95_regexec(constregex_t*preg,constchar*string,size_tnmatch,
153-
regmatch_t*pmatch,inteflags)
152+
pg_regexec(constregex_t*preg,constchar*string,size_tnmatch,
153+
regmatch_t*pmatch,inteflags)
154154
{
155155
structre_guts*g=preg->re_g;
156156

‎src/backend/regex/regfree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* regfree - free everything
5050
*/
5151
void
52-
pg95_regfree(regex_t*preg)
52+
pg_regfree(regex_t*preg)
5353
{
5454
structre_guts*g;
5555

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp