Skip to content

Commit 6969b8f

Browse files
author
Thomas G. Lockhart
committed
Repair usage of the OVERLAPS operator.
Allow some operator-like tokens to be used as function names. Flesh out support for time, timetz, and interval operators and interactions. Regression tests pass, but non-reference-platform horology test results will need to be updated.
1 parent 1131261 commit 6969b8f

File tree

11 files changed

+1032
-203
lines changed

11 files changed

+1032
-203
lines changed

src/backend/parser/gram.y

Lines changed: 66 additions & 30 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.210 2000/11/24 20:16:39 petere Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.211 2000/12/03 14:50:54 thomas Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -198,8 +198,9 @@ static void doNegateFloat(Value *v);
198198
%type <jtype> join_type
199199

200200
%type <list> extract_list, position_list
201-
%type <list> substr_list, substr_from, substr_for, trim_list
201+
%type <list> substr_list, trim_list
202202
%type <list> opt_interval
203+
%type <node> substr_from, substr_for
203204

204205
%type <boolean> opt_inh_star, opt_binary, opt_using, opt_instead, opt_only
205206
opt_with_copy, index_opt_unique, opt_verbose, opt_analyze
@@ -330,7 +331,7 @@ static void doNegateFloat(Value *v);
330331
* when some sort of pg_privileges relation is introduced.
331332
* - Todd A. Brandys 1998-01-01?
332333
*/
333-
%token ABORT_TRANS, ACCESS, AFTER, AGGREGATE, ANALYZE, ANALYSE,
334+
%token ABORT_TRANS, ACCESS, AFTER, AGGREGATE, ANALYSE, ANALYZE,
334335
BACKWARD, BEFORE, BINARY, BIT,
335336
CACHE, CHECKPOINT, CLUSTER, COMMENT, COPY, CREATEDB, CREATEUSER, CYCLE,
336337
DATABASE, DELIMITERS, DO,
@@ -4873,17 +4874,20 @@ c_expr: attr
48734874
| SUBSTRING '(' substr_list ')'
48744875
{
48754876
/* substring(A from B for C) is converted to
4876-
* substring(A, B, C) */
4877+
* substring(A, B, C) - thomas 2000-11-28
4878+
*/
48774879
FuncCall *n = makeNode(FuncCall);
48784880
n->funcname = "substring";
48794881
n->args = $3;
48804882
n->agg_star = FALSE;
48814883
n->agg_distinct = FALSE;
48824884
$$ = (Node *)n;
48834885
}
4884-
/* various trim expressions are defined in SQL92 - thomas 1997-07-19 */
48854886
| TRIM '(' BOTH trim_list ')'
48864887
{
4888+
/* various trim expressions are defined in SQL92
4889+
* - thomas 1997-07-19
4890+
*/
48874891
FuncCall *n = makeNode(FuncCall);
48884892
n->funcname = "btrim";
48894893
n->args = $4;
@@ -4994,29 +4998,49 @@ position_list: b_expr IN b_expr
49944998
{ $$ = NIL; }
49954999
;
49965000

4997-
substr_list: expr_list substr_from substr_for
5001+
/* SUBSTRING() arguments
5002+
* SQL9x defines a specific syntax for arguments to SUBSTRING():
5003+
* o substring(text from int for int)
5004+
* o substring(text from int) get entire string from starting point "int"
5005+
* o substring(text for int) get first "int" characters of string
5006+
* We also want to implement generic substring functions which accept
5007+
* the usual generic list of arguments. So we will accept both styles
5008+
* here, and convert the SQL9x style to the generic list for further
5009+
* processing. - thomas 2000-11-28
5010+
*/
5011+
substr_list: a_expr substr_from substr_for
49985012
{
4999-
$$ = nconc(nconc($1,$2),$3);
5013+
$$ = makeList3($1, $2, $3);
50005014
}
5001-
| /*EMPTY*/
5002-
{ $$ = NIL; }
5003-
;
5004-
5005-
substr_from: FROM expr_list
5006-
{ $$ = $2; }
5007-
| /*EMPTY*/
5015+
| a_expr substr_for substr_from
5016+
{
5017+
$$ = makeList3($1, $3, $2);
5018+
}
5019+
| a_expr substr_from
5020+
{
5021+
$$ = makeList2($1, $2);
5022+
}
5023+
| a_expr substr_for
50085024
{
50095025
A_Const *n = makeNode(A_Const);
50105026
n->val.type = T_Integer;
50115027
n->val.val.ival = 1;
5012-
$$ = makeList1((Node *)n);
5028+
$$ = makeList3($1, (Node *)n, $2);
5029+
}
5030+
| expr_list
5031+
{
5032+
$$ = $1;
50135033
}
5034+
| /*EMPTY*/
5035+
{ $$ = NIL; }
50145036
;
50155037

5016-
substr_for: FOR expr_list
5038+
substr_from: FROM a_expr
5039+
{ $$ = $2; }
5040+
;
5041+
5042+
substr_for: FOR a_expr
50175043
{ $$ = $2; }
5018-
| /*EMPTY*/
5019-
{ $$ = NIL; }
50205044
;
50215045

50225046
trim_list: a_expr FROM expr_list
@@ -5241,6 +5265,7 @@ relation_name: SpecialRuleRelation
52415265
}
52425266
;
52435267

5268+
name: ColId { $$ = $1; };
52445269
database_name: ColId { $$ = $1; };
52455270
access_method: ColId { $$ = $1; };
52465271
attr_name: ColId { $$ = $1; };
@@ -5250,9 +5275,27 @@ index_name: ColId { $$ = $1; };
52505275
/* Functions
52515276
* Include date/time keywords as SQL92 extension.
52525277
* Include TYPE as a SQL92 unreserved keyword. - thomas 1997-10-05
5278+
* Any tokens which show up as operators will screw up the parsing if
5279+
* allowed as identifiers, but are acceptable as ColLabels:
5280+
* BETWEEN, IN, IS, ISNULL, NOTNULL, OVERLAPS
5281+
* Thanks to Tom Lane for pointing this out. - thomas 2000-03-29
5282+
* We need OVERLAPS allowed as a function name to enable the implementation
5283+
* of argument type variations on the underlying implementation. These
5284+
* variations are done as SQL-language entries in the pg_proc catalog.
5285+
* Do not include SUBSTRING here since it has explicit productions
5286+
* in a_expr to support the goofy SQL9x argument syntax.
5287+
* - thomas 2000-11-28
52535288
*/
5254-
name: ColId { $$ = $1; };
5255-
func_name: ColId { $$ = xlateSqlFunc($1); };
5289+
func_name: ColId { $$ = xlateSqlFunc($1); }
5290+
| BETWEEN { $$ = xlateSqlFunc("between"); }
5291+
| ILIKE { $$ = xlateSqlFunc("ilike"); }
5292+
| IN { $$ = xlateSqlFunc("in"); }
5293+
| IS { $$ = xlateSqlFunc("is"); }
5294+
| ISNULL { $$ = xlateSqlFunc("isnull"); }
5295+
| LIKE { $$ = xlateSqlFunc("like"); }
5296+
| NOTNULL { $$ = xlateSqlFunc("notnull"); }
5297+
| OVERLAPS { $$ = xlateSqlFunc("overlaps"); }
5298+
;
52565299

52575300
file_name: Sconst { $$ = $1; };
52585301

@@ -5358,14 +5401,6 @@ UserId: ColId { $$ = $1; };
53585401
* some of these keywords will have to be removed from this
53595402
* list due to shift/reduce conflicts in yacc. If so, move
53605403
* down to the ColLabel entity. - thomas 1997-11-06
5361-
* Any tokens which show up as operators will screw up the parsing if
5362-
* allowed as identifiers, but are acceptable as ColLabels:
5363-
* BETWEEN, IN, IS, ISNULL, NOTNULL, OVERLAPS
5364-
* Thanks to Tom Lane for pointing this out. - thomas 2000-03-29
5365-
* Allow LIKE and ILIKE as TokenId (and ColId) to make sure that they
5366-
* are allowed in the func_name production. Otherwise, we can't define
5367-
* more like() and ilike() functions for new data types.
5368-
* - thomas 2000-08-07
53695404
*/
53705405
ColId: generic { $$ = $1; }
53715406
| datetime { $$ = $1; }
@@ -5428,7 +5463,6 @@ TokenId: ABSOLUTE { $$ = "absolute"; }
54285463
| FUNCTION { $$ = "function"; }
54295464
| GRANT { $$ = "grant"; }
54305465
| HANDLER { $$ = "handler"; }
5431-
| ILIKE { $$ = "ilike"; }
54325466
| IMMEDIATE { $$ = "immediate"; }
54335467
| INCREMENT { $$ = "increment"; }
54345468
| INDEX { $$ = "index"; }
@@ -5441,7 +5475,6 @@ TokenId: ABSOLUTE { $$ = "absolute"; }
54415475
| LANGUAGE { $$ = "language"; }
54425476
| LANCOMPILER { $$ = "lancompiler"; }
54435477
| LEVEL { $$ = "level"; }
5444-
| LIKE { $$ = "like"; }
54455478
| LOCATION { $$ = "location"; }
54465479
| MATCH { $$ = "match"; }
54475480
| MAXVALUE { $$ = "maxvalue"; }
@@ -5571,6 +5604,7 @@ ColLabel: ColId { $$ = $1; }
55715604
| GLOBAL { $$ = "global"; }
55725605
| GROUP { $$ = "group"; }
55735606
| HAVING { $$ = "having"; }
5607+
| ILIKE { $$ = "ilike"; }
55745608
| INITIALLY { $$ = "initially"; }
55755609
| IN { $$ = "in"; }
55765610
| INNER_P { $$ = "inner"; }
@@ -5582,6 +5616,8 @@ ColLabel: ColId { $$ = $1; }
55825616
| JOIN { $$ = "join"; }
55835617
| LEADING { $$ = "leading"; }
55845618
| LEFT { $$ = "left"; }
5619+
| LIKE { $$ = "like"; }
5620+
| LIMIT { $$ = "limit"; }
55855621
| LISTEN { $$ = "listen"; }
55865622
| LOAD { $$ = "load"; }
55875623
| LOCAL { $$ = "local"; }

src/backend/utils/adt/date.c

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.52 2000/11/11 19:55:19 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.53 2000/12/03 14:51:01 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -594,7 +594,6 @@ timestamp_time(PG_FUNCTION_ARGS)
594594
PG_RETURN_TIMEADT(result);
595595
}
596596

597-
598597
/* datetime_timestamp()
599598
* Convert date and time to timestamp data type.
600599
*/
@@ -612,7 +611,6 @@ datetime_timestamp(PG_FUNCTION_ARGS)
612611
PG_RETURN_TIMESTAMP(result);
613612
}
614613

615-
616614
/* time_interval()
617615
* Convert time to interval data type.
618616
*/
@@ -630,6 +628,72 @@ time_interval(PG_FUNCTION_ARGS)
630628
PG_RETURN_INTERVAL_P(result);
631629
}
632630

631+
/* interval_time()
632+
* Convert interval to time data type.
633+
*/
634+
Datum
635+
interval_time(PG_FUNCTION_ARGS)
636+
{
637+
Interval *span = PG_GETARG_INTERVAL_P(0);
638+
TimeADT result;
639+
Interval span1;
640+
641+
result = span->time;
642+
TMODULO(result, span1.time, 86400e0);
643+
644+
PG_RETURN_TIMEADT(result);
645+
}
646+
647+
/* time_pl_interval()
648+
* Add interval to time.
649+
*/
650+
Datum
651+
time_pl_interval(PG_FUNCTION_ARGS)
652+
{
653+
TimeADT time = PG_GETARG_TIMEADT(0);
654+
Interval *span = PG_GETARG_INTERVAL_P(1);
655+
TimeADT result;
656+
TimeADT time1;
657+
658+
result = (time + span->time);
659+
TMODULO(result, time1, 86400e0);
660+
if (result < 0)
661+
result += 86400;
662+
663+
PG_RETURN_TIMEADT(result);
664+
}
665+
666+
/* time_mi_interval()
667+
* Subtract interval from time.
668+
*/
669+
Datum
670+
time_mi_interval(PG_FUNCTION_ARGS)
671+
{
672+
TimeADT time = PG_GETARG_TIMEADT(0);
673+
Interval *span = PG_GETARG_INTERVAL_P(1);
674+
TimeADT result;
675+
TimeADT time1;
676+
677+
result = (time - span->time);
678+
TMODULO(result, time1, 86400e0);
679+
if (result < 0)
680+
result += 86400;
681+
682+
PG_RETURN_TIMEADT(result);
683+
}
684+
685+
/* interval_pl_time()
686+
* Add time to interval.
687+
*/
688+
Datum
689+
interval_pl_time(PG_FUNCTION_ARGS)
690+
{
691+
Datum span = PG_GETARG_DATUM(0);
692+
Datum time = PG_GETARG_DATUM(1);
693+
694+
return DirectFunctionCall2(time_pl_interval, time, span);
695+
}
696+
633697

634698
/* time_text()
635699
* Convert time to text data type.
@@ -856,6 +920,50 @@ timetz_smaller(PG_FUNCTION_ARGS)
856920
PG_RETURN_TIMETZADT_P(time2);
857921
}
858922

923+
/* timetz_pl_interval()
924+
* Add interval to timetz.
925+
*/
926+
Datum
927+
timetz_pl_interval(PG_FUNCTION_ARGS)
928+
{
929+
TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
930+
Interval *span = PG_GETARG_INTERVAL_P(1);
931+
TimeTzADT *result;
932+
TimeTzADT time1;
933+
934+
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
935+
936+
result->time = (time->time + span->time);
937+
TMODULO(result->time, time1.time, 86400e0);
938+
if (result->time < 0)
939+
result->time += 86400;
940+
result->zone = time->zone;
941+
942+
PG_RETURN_TIMETZADT_P(result);
943+
}
944+
945+
/* timetz_mi_interval()
946+
* Subtract interval from timetz.
947+
*/
948+
Datum
949+
timetz_mi_interval(PG_FUNCTION_ARGS)
950+
{
951+
TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
952+
Interval *span = PG_GETARG_INTERVAL_P(1);
953+
TimeTzADT *result;
954+
TimeTzADT time1;
955+
956+
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
957+
958+
result->time = (time->time - span->time);
959+
TMODULO(result->time, time1.time, 86400e0);
960+
if (result->time < 0)
961+
result->time += 86400;
962+
result->zone = time->zone;
963+
964+
PG_RETURN_TIMETZADT_P(result);
965+
}
966+
859967
/* overlaps_timetz()
860968
* Implements the SQL92 OVERLAPS operator.
861969
* Algorithm from Date and Darwen, 1997

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-2000, PostgreSQL, Inc
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $Id: catversion.h,v 1.65 2000/11/30 01:47:33 vadim Exp $
40+
* $Id: catversion.h,v 1.66 2000/12/03 14:51:09 thomas Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200011291
56+
#define CATALOG_VERSION_NO 200012030
5757

5858
#endif

src/include/catalog/pg_operator.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: pg_operator.h,v 1.84 2000/11/21 03:23:19 tgl Exp $
11+
* $Id: pg_operator.h,v 1.85 2000/12/03 14:51:09 thomas Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -745,13 +745,20 @@ DATA(insert OID = 1795 ( "<<" PGUID 0 b t f 1560 23 1560 0 0 0 0 bits
745745
DATA(insert OID = 1796 ( ">>" PGUID 0 b t f 1560 23 1560 0 0 0 0 bitshiftright - - ));
746746
DATA(insert OID = 1797 ( "||" PGUID 0 b t f 1560 1560 1560 0 0 0 0 bitcat - - ));
747747

748+
DATA(insert OID = 1800 ( "+" PGUID 0 b t f 1083 1186 1083 0 0 0 0 time_pl_interval - - ));
749+
DATA(insert OID = 1801 ( "-" PGUID 0 b t f 1083 1186 1083 0 0 0 0 time_mi_interval - - ));
750+
DATA(insert OID = 1802 ( "+" PGUID 0 b t f 1266 1186 1266 0 0 0 0 timetz_pl_interval - - ));
751+
DATA(insert OID = 1803 ( "-" PGUID 0 b t f 1266 1186 1266 0 0 0 0 timetz_mi_interval - - ));
752+
748753
DATA(insert OID = 1804 ( "=" PGUID 0 b t f 1562 1562 16 1804 1805 1806 1806 varbiteq eqsel eqjoinsel ));
749754
DATA(insert OID = 1805 ( "<>" PGUID 0 b t f 1562 1562 16 1805 1804 0 0 varbitne neqsel neqjoinsel ));
750755
DATA(insert OID = 1806 ( "<" PGUID 0 b t f 1562 1562 16 1807 1809 0 0 varbitlt scalarltsel scalarltjoinsel ));
751756
DATA(insert OID = 1807 ( ">" PGUID 0 b t f 1562 1562 16 1806 1808 0 0 varbitgt scalargtsel scalargtjoinsel ));
752757
DATA(insert OID = 1808 ( "<=" PGUID 0 b t f 1562 1562 16 1809 1807 0 0 varbitle scalarltsel scalarltjoinsel ));
753758
DATA(insert OID = 1809 ( ">=" PGUID 0 b t f 1562 1562 16 1808 1806 0 0 varbitge scalargtsel scalargtjoinsel ));
754759

760+
DATA(insert OID = 1849 ( "+" PGUID 0 b t f 1186 1083 1083 0 0 0 0 interval_pl_time - - ));
761+
755762
DATA(insert OID = 1862 ( "=" PGUID 0 b t f 21 20 16 1868 1863 95 412 int28eq eqsel eqjoinsel ));
756763
DATA(insert OID = 1863 ( "<>" PGUID 0 b t f 21 20 16 1869 1862 0 0 int28ne neqsel neqjoinsel ));
757764
DATA(insert OID = 1864 ( "<" PGUID 0 b t f 21 20 16 1871 1867 0 0 int28lt scalarltsel scalarltjoinsel ));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy