Skip to content

Commit a5e6e99

Browse files
committed
Allow schema-qualified operator names to be used in the optional
arguments of CREATE OPERATOR.
1 parent f1d8204 commit a5e6e99

File tree

4 files changed

+55
-56
lines changed

4 files changed

+55
-56
lines changed

doc/src/sgml/ref/create_operator.sgml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_operator.sgml,v 1.29 2002/05/18 15:44:47 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_operator.sgml,v 1.30 2002/08/10 19:01:53 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -437,6 +437,15 @@ MYBOXES.description === box '((0,0), (1,1))'
437437
Refer to <command>DROP OPERATOR</command> to delete
438438
user-defined operators from a database.
439439
</para>
440+
441+
<para>
442+
To give a schema-qualified operator name in <replaceable
443+
class="parameter">com_op</replaceable> or the other optional
444+
arguments, use the <literal>OPERATOR()</> syntax, for example
445+
<programlisting>
446+
COMMUTATOR = OPERATOR(myschema.===) ,
447+
</programlisting>
448+
</para>
440449
</refsect2>
441450
</refsect1>
442451

doc/src/sgml/syntax.sgml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.64 2002/08/05 19:43:31 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.65 2002/08/10 19:01:53 tgl Exp $
33
-->
44

55
<chapter id="sql-syntax">
@@ -755,7 +755,7 @@ SELECT (5 !) - 6;
755755
</row>
756756

757757
<row>
758-
<entry><token>LIKE</token> <token>ILIKE</token></entry>
758+
<entry><token>LIKE</token> <token>ILIKE</token> <token>SIMILAR</token></entry>
759759
<entry></entry>
760760
<entry>string pattern matching</entry>
761761
</row>
@@ -801,6 +801,17 @@ SELECT (5 !) - 6;
801801
the same precedence as the built-in <quote>+</quote> operator, no
802802
matter what yours does.
803803
</para>
804+
805+
<para>
806+
When a schema-qualified operator name is used in the
807+
<literal>OPERATOR</> syntax, as for example in
808+
<programlisting>
809+
SELECT 3 OPERATOR(pg_catalog.+) 4;
810+
</programlisting>
811+
the <literal>OPERATOR</> construct is taken to have the default precedence
812+
shown above for <quote>any other</> operator. This is true no matter
813+
which specific operator name appears inside <literal>OPERATOR()</>.
814+
</para>
804815
</sect2>
805816
</sect1>
806817

src/backend/commands/define.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.78 2002/06/20 20:29:27 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.79 2002/08/10 19:01:53 tgl Exp $
1313
*
1414
* DESCRIPTION
1515
* The "DefineFoo" routines take the parse tree and pick out the
@@ -35,6 +35,7 @@
3535
#include <ctype.h>
3636
#include <math.h>
3737

38+
#include "catalog/namespace.h"
3839
#include "commands/defrem.h"
3940
#include "parser/parse_type.h"
4041
#include "utils/int8.h"
@@ -86,6 +87,8 @@ defGetString(DefElem *def)
8687
return strVal(def->arg);
8788
case T_TypeName:
8889
return TypeNameToString((TypeName *) def->arg);
90+
case T_List:
91+
return NameListToString((List *) def->arg);
8992
default:
9093
elog(ERROR, "Define: cannot interpret argument of \"%s\"",
9194
def->defname);
@@ -156,6 +159,8 @@ defGetQualifiedName(DefElem *def)
156159
{
157160
case T_TypeName:
158161
return ((TypeName *) def->arg)->names;
162+
case T_List:
163+
return (List *) def->arg;
159164
case T_String:
160165
/* Allow quoted name for backwards compatibility */
161166
return makeList1(def->arg);
@@ -168,6 +173,9 @@ defGetQualifiedName(DefElem *def)
168173

169174
/*
170175
* Extract a TypeName from a DefElem.
176+
*
177+
* Note: we do not accept a List arg here, because the parser will only
178+
* return a bare List when the name looks like an operator name.
171179
*/
172180
TypeName *
173181
defGetTypeName(DefElem *def)
@@ -223,11 +231,14 @@ defGetTypeLength(DefElem *def)
223231
"variable") == 0)
224232
return -1; /* variable length */
225233
break;
234+
case T_List:
235+
/* must be an operator name */
236+
break;
226237
default:
227238
elog(ERROR, "Define: cannot interpret argument of \"%s\"",
228239
def->defname);
229240
}
230-
elog(ERROR, "Define: invalid argument for \"%s\"",
231-
def->defname);
241+
elog(ERROR, "Define: invalid argument for \"%s\": \"%s\"",
242+
def->defname, defGetString(def));
232243
return 0; /* keep compiler quiet */
233244
}

src/backend/parser/gram.y

Lines changed: 18 additions & 50 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.357 2002/08/06 05:40:45 ishii Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.358 2002/08/10 19:01:53 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -1307,27 +1307,19 @@ copy_opt_list:
13071307
copy_opt_item:
13081308
BINARY
13091309
{
1310-
$$ = makeNode(DefElem);
1311-
$$->defname = "binary";
1312-
$$->arg = (Node *)makeInteger(TRUE);
1310+
$$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
13131311
}
13141312
| OIDS
13151313
{
1316-
$$ = makeNode(DefElem);
1317-
$$->defname = "oids";
1318-
$$->arg = (Node *)makeInteger(TRUE);
1314+
$$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
13191315
}
13201316
| DELIMITER opt_as Sconst
13211317
{
1322-
$$ = makeNode(DefElem);
1323-
$$->defname = "delimiter";
1324-
$$->arg = (Node *)makeString($3);
1318+
$$ = makeDefElem("delimiter", (Node *)makeString($3));
13251319
}
13261320
| NULL_P opt_as Sconst
13271321
{
1328-
$$ = makeNode(DefElem);
1329-
$$->defname = "null";
1330-
$$->arg = (Node *)makeString($3);
1322+
$$ = makeDefElem("null", (Node *)makeString($3));
13311323
}
13321324
;
13331325

@@ -1336,19 +1328,15 @@ copy_opt_item:
13361328
opt_binary:
13371329
BINARY
13381330
{
1339-
$$ = makeNode(DefElem);
1340-
$$->defname = "binary";
1341-
$$->arg = (Node *)makeInteger(TRUE);
1331+
$$ = makeDefElem("binary", (Node *)makeInteger(TRUE));
13421332
}
13431333
| /*EMPTY*/ { $$ = NULL; }
13441334
;
13451335

13461336
opt_oids:
13471337
WITH OIDS
13481338
{
1349-
$$ = makeNode(DefElem);
1350-
$$->defname = "oids";
1351-
$$->arg = (Node *)makeInteger(TRUE);
1339+
$$ = makeDefElem("oids", (Node *)makeInteger(TRUE));
13521340
}
13531341
| /*EMPTY*/ { $$ = NULL; }
13541342
;
@@ -1357,9 +1345,7 @@ copy_delimiter:
13571345
/* USING DELIMITERS kept for backward compatibility. 2002-06-15 */
13581346
opt_using DELIMITERS Sconst
13591347
{
1360-
$$ = makeNode(DefElem);
1361-
$$->defname = "delimiter";
1362-
$$->arg = (Node *)makeString($3);
1348+
$$ = makeDefElem("delimiter", (Node *)makeString($3));
13631349
}
13641350
| /*EMPTY*/ { $$ = NULL; }
13651351
;
@@ -2276,7 +2262,7 @@ def_elem: ColLabel '=' def_arg
22762262

22772263
/* Note: any simple identifier will be returned as a type name! */
22782264
def_arg: func_return { $$ = (Node *)$1; }
2279-
| all_Op { $$ = (Node *)makeString($1); }
2265+
| qual_all_Op { $$ = (Node *)$1; }
22802266
| NumericOnly { $$ = (Node *)$1; }
22812267
| Sconst { $$ = (Node *)makeString($1); }
22822268
;
@@ -3568,27 +3554,19 @@ createdb_opt_list:
35683554
createdb_opt_item:
35693555
LOCATION opt_equal Sconst
35703556
{
3571-
$$ = makeNode(DefElem);
3572-
$$->defname = "location";
3573-
$$->arg = (Node *)makeString($3);
3557+
$$ = makeDefElem("location", (Node *)makeString($3));
35743558
}
35753559
| LOCATION opt_equal DEFAULT
35763560
{
3577-
$$ = makeNode(DefElem);
3578-
$$->defname = "location";
3579-
$$->arg = NULL;
3561+
$$ = makeDefElem("location", NULL);
35803562
}
35813563
| TEMPLATE opt_equal name
35823564
{
3583-
$$ = makeNode(DefElem);
3584-
$$->defname = "template";
3585-
$$->arg = (Node *)makeString($3);
3565+
$$ = makeDefElem("template", (Node *)makeString($3));
35863566
}
35873567
| TEMPLATE opt_equal DEFAULT
35883568
{
3589-
$$ = makeNode(DefElem);
3590-
$$->defname = "template";
3591-
$$->arg = NULL;
3569+
$$ = makeDefElem("template", NULL);
35923570
}
35933571
| ENCODING opt_equal Sconst
35943572
{
@@ -3598,9 +3576,7 @@ createdb_opt_item:
35983576
elog(ERROR, "%s is not a valid encoding name", $3);
35993577
encoding = pg_char_to_encoding($3);
36003578

3601-
$$ = makeNode(DefElem);
3602-
$$->defname = "encoding";
3603-
$$->arg = (Node *)makeInteger(encoding);
3579+
$$ = makeDefElem("encoding", (Node *)makeInteger(encoding));
36043580
}
36053581
| ENCODING opt_equal Iconst
36063582
{
@@ -3610,27 +3586,19 @@ createdb_opt_item:
36103586
if (!strcmp(encoding_name,"") ||
36113587
pg_valid_server_encoding(encoding_name) < 0)
36123588
elog(ERROR, "%d is not a valid encoding code", $3);
3613-
$$ = makeNode(DefElem);
3614-
$$->defname = "encoding";
3615-
$$->arg = (Node *)makeInteger($3);
3589+
$$ = makeDefElem("encoding", (Node *)makeInteger($3));
36163590
}
36173591
| ENCODING opt_equal DEFAULT
36183592
{
3619-
$$ = makeNode(DefElem);
3620-
$$->defname = "encoding";
3621-
$$->arg = (Node *)makeInteger(-1);
3593+
$$ = makeDefElem("encoding", (Node *)makeInteger(-1));
36223594
}
36233595
| OWNER opt_equal name
36243596
{
3625-
$$ = makeNode(DefElem);
3626-
$$->defname = "owner";
3627-
$$->arg = (Node *)makeString($3);
3597+
$$ = makeDefElem("owner", (Node *)makeString($3));
36283598
}
36293599
| OWNER opt_equal DEFAULT
36303600
{
3631-
$$ = makeNode(DefElem);
3632-
$$->defname = "owner";
3633-
$$->arg = NULL;
3601+
$$ = makeDefElem("owner", NULL);
36343602
}
36353603
;
36363604

0 commit comments

Comments
 (0)