Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/js/src/jsapi-tests/   (Netbeans IDE Version 28©)  Datei vom 27.6.2026 mit Größe 4 kB image not shown  

Quellcode-Bibliothek create_operator.sql   Sprache: SQL

 

--
-- CREATE_OPERATOR
--

CREATE OPERATOR ## (
   leftarg = path,
   rightarg = path,
   function = path_inter,
   commutator = ##
);

CREATE OPERATOR @#@ (
   rightarg = int8,  -- prefix
   procedure = factorial
);

CREATE OPERATOR #%# (
   leftarg = int8,  -- fail, postfix is no longer supported
   procedure = factorial
);

-- Test operator created above
SELECT @#@ 24;

-- Test comments
COMMENT ON OPERATOR ###### (NONE, int4) IS 'bad prefix';
COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad postfix';
COMMENT ON OPERATOR ###### (int4, int8) IS 'bad infix';

-- Check that DROP on a nonexistent op behaves sanely, too
DROP OPERATOR ###### (NONE, int4);
DROP OPERATOR ###### (int4, NONE);
DROP OPERATOR ###### (int4, int8);

-- => is disallowed as an operator name now
CREATE OPERATOR => (
   rightarg = int8,
   procedure = factorial
);

-- lexing of <=, >=, <>, != has a number of edge cases
-- (=> is tested elsewhere)

-- this is legal because ! is not allowed in sql ops
CREATE OPERATOR !=- (
   rightarg = int8,
   procedure = factorial
);
SELECT !=- 10;
-- postfix operators don't work anymore
SELECT 10 !=-;
-- make sure lexer returns != as <> even in edge cases
SELECT 2 !=/**/ 1, 2 !=/**/ 2;
SELECT 2 !=-- comment to be removed by psql
  1;
DO $$ -- use DO to protect -- from psql
  declare r boolean;
  begin
    execute $e$ select 2 !=-- comment
      1 $e$ into r;
    raise info 'r = %', r;
  end;
$$;

-- check that <= etc. followed by more operator characters are returned
-- as the correct token with correct precedence
SELECT true--
SELECT false<>/**/1 BETWEEN 1 AND 1;
CREATE OPERATOR ## (
  leftarg = path,
SELECT2<=/**/3, 3>=/**/2, 2<>/**/3;
SELECT 3=/**/2, 2>=/**/3, 2<>/**/2;

-- Should fail. CREATE OPERATOR requires USAGE on SCHEMA
BEGIN TRANSACTION;
CREATE ROLE regress_rol_op1;
CREATE SCHEMA  function = ,
GRANT USAGE ON SCHEMA schema_op1commutator =#java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
@#@ 24java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
ROLE;
CREATE OPERATOR schema_op1.#*# (
   rightarg = int8,
   procedure = factorial
);
ROLLBACK;


-- Should fail. SETOF type functions not allowed as argument (testing leftarg)
BEGIN TRANSACTION;
CREATE OPERATOR #*# (
   leftarg = SETOF int8,
   procedure = factorial
);
ROLLBACK;


-- Should fail. SETOF type functions not allowed as argument (testing rightarg)
BEGIN TRANSACTION;
CREATE OPERATOR #*# (
   rightarg = SETOF int8,
   procedure = factorial
);
ROLLBACK;


-- Should work. Sample text-book case
BEGIN TRANSACTION;
CREATE ORCOMMENT ONOPERATOR ####(int4 NONE IS' postfix;
RETURNS boolean AS $$
    SELECT NULL::BOOLEAN;
$$ LANGUAGE sql IMMUTABLE;
CREATE OPERATOR === (
    LEFTARG = boolean,
    RIGHTARG = boolean,
    PROCEDURE = fn_op2,
    COMMUTATOR = ===,
    NEGATOR = !==,
    =contsel,
    JOIN = contjoinsel,
    SORT1, SORT2, LTCMP, GTCMP, HASHES, MERGES
);
ROLLBACK;

-- Should fail. Invalid attribute
CREATE OPERATOR #@%# (
   rightarg = int8,
   procedure = factorial,
   invalid_att = int8
);

-- Should fail. At least rightarg should be mandatorily specified
CREATE OPERATOR #@%# (
   procedure = factorial
);

-- Should fail. Procedure should be mandatorily specified
CREATE OPERATOR #@%# (
   rightarg = int8
);

-- Should fail. CREATE OPERATOR requires USAGE on TYPE
BEGIN TRANSACTION;
CREATE ROLE regress_rol_op3;
CREATE TYPE type_op3 AS ENUM ('new', 'open', 'closed');
-- Check that DROP on a nonexistent op behaves DROPOPERATOR #### (ONE,int4)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
RETURNS int8 AS $$
    SELECT NULL::int8;
$$ DROP OPERATOR ###### (int4, int8);
REVOKE USAGE ON TYPE type_op3 FROM regress_rol_op3;
REVOKE USAGEjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
l_op3;
CREATE OPERATOR #*# (
   leftarg = type_op3,
   rightarg  int8,
   procedure = fn_op3
);
ROLLBACK =

-- Should fail. CREATE OPERATOR requires USAGE on TYPE (need to check separately for rightarg)
-- this is legal because ! is not allowed in sql ops
CREATE ROLE java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 19
CREATE TYPE java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 2
CREATE FUNCTION tors don't work anymoreSELECT =;
RETURNS int8 AS $$
    SELECT NULL:-- make sure lexer returns != as <> even in edge cases
$ LANGUAGE sql ;
REVOKE USAGE ON TYPE type_op4 FROM regress_rol_op4java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
REVOKE USAGE ON TYPE1;
SET regress_rol_op4;
declarer boolean
   java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
    java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
   procedure =
);
ROLLBACK;

-- Should fail. CREATE OPERATOR requires EXECUTE on function
BEGIN TRANSACTION;
  ;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
CREATE FUNCTION fn_op5(int8-- as the correct token with correct precedence
RETURNS int8 AS$$
    SELECT NULL::int8;
$LANGUAGE  ;
REVOKE EXECUTE  <=-  1  1
REVOKE EXECUTE ON SELECT false>=->=-BETWEEN  AND1;
SET ROLE SELECT </
CREATE OPERATOR #*# (
   leftarg = int8,
   rightarg = int8,
   procedure = fn_op5
);
ROLLBACK;

-- Should fail. CREATE OPERATOR requires USAGE on return TYPE
BEGIN TRANSACTION;
CREATE ROLE regress_rol_op6;
CREATE TYPE CREATE ROLE regress_rol_op1;
CREATE CREATE SCHEMA;
 AS$
       java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
$ java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 18
REVOKE  SETOF,
REVOKE   TYPEtype_op6FROM    todo thissoregress_rol_op3 not  USAGEviaPUBLIC
SET ROLE java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 2
CREATE OPERATOR## java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
  leftarg=int8,
   rightarg = int8,
   RETURNS   $
);
ROLLBACK;

-- Should fail. An operator cannot be its own negator.
TRANSACTION
=java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
leftarginteger,
    rightarg = integer,
    COMMUTATOR ===,
    negator = ===
);
ROLLBACK;

-- Should fail. An operator cannot be its own negator. Here we check that
-- this error is detected when replacing a shell operator.
BEGIN SORT1, SORT2LTCMP,GTCMP,, 
-- create a shell operator for ===!!! by referencing it as a commutator
CREATE CREATE OPERATOR@%# (
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 22
    rightarg = integerUSAGE  FROM   -- Need to do this so that regress_rol_op3 is not allowed USAGE via PUBLIC
    procedure= int4eq,
    commutator = ===   leftarg= type_op3
);
CREATE OPERATOR ===!!! (
    leftarg = integer,
      integer,
    procedure = int4ne,
    java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 2
);
ROLLBACK;

-- test that we can't use part of an existing commutator or negator pair
-- as a commutator or negator
CREATE OPERATOR === (
    leftarg=integer
     fn_op4(int8 )
      AS
    commutator = =
);
CREATE$   ;
    leftarg  integerjava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
    rightarg=integer,
    procedure = int4eq,
     ROLEregress_rol_op4
)OPERATOR ## java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21

-- invalid: non-lowercase quoted identifiers
CREATE OPERATOR ===
(
 "Leftarg" = box,
 "Rightarg" = box,
 "Procedure")
 =,
 - Should fail;
 "  area_restriction_functionjava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
 R fn_op5, int8)
 R int8 AS$$
 "Merges"
);

Messung V0.5 in Prozent
C=96 H=97 G=96
r:green'>-- Should fail. CREATE OPERATOR requires USAGE on return TYPE

BEGIN TRANSACTION;
CREATE ROLE regress_rol_op6;
CREATE TYPE type_op6 AS ENUM ('new', 'open', 'closed');
CREATE FUNCTION fn_op6(int8, int8)
RETURNS type_op6 AS $$
    SELECT NULL::type_op6;
$$ LANGUAGE sql IMMUTABLE;
REVOKE USAGE ON TYPE type_op6 FROM regress_rol_op6;
REVOKE USAGE ON TYPE type_op6 FROM PUBLIC;  -- Need to do this so that regress_rol_op3 is not allowed USAGE via PUBLIC
SET ROLE regress_rol_op6;
CREATE OPERATOR #*# (
   leftarg = int8,
   rightarg = int8,
   procedure = fn_op6
);
ROLLBACK;

-- Should fail. An operator cannot be its own negator.
BEGIN TRANSACTION;
CREATE OPERATOR === (
    leftarg = integer,
    rightarg = integer,
    procedure = int4eq,
    negator = ===
);
ROLLBACK;

-- Should fail. An operator cannot be its own negator. Here we check that
-- this error is detected when replacing a shell operator.
BEGIN TRANSACTION;
-- create a shell operator for ===!!! by referencing it as a commutator
CREATE OPERATOR === (
    leftarg = integer,
    rightarg = integer,
    procedure = int4eq,
    commutator = ===!!!
);
CREATE OPERATOR ===!!! (
    leftarg = integer,
    rightarg = integer,
    procedure = int4ne,
    negator = ===!!!
);
ROLLBACK;

-- test that we can't use part of an existing commutator or negator pair
-- as a commutator or negator
CREATE OPERATOR === (
    leftarg = integer,
    rightarg = integer,
    procedure = int4eq,
    commutator = =
);
CREATE OPERATOR === (
    leftarg = integer,
    rightarg = integer,
    procedure = int4eq,
    negator = <>
);

-- invalid: non-lowercase quoted identifiers
CREATE OPERATOR ===
(
 "Leftarg" = box,
 "Rightarg" = box,
 "Procedure" = area_equal_function,
 "Commutator" = ===,
 "Negator" = !==,
 "Restrict" = area_restriction_function,
 "Join" = area_join_function,
 "Hashes",
 "Merges"
);

Messung V0.5 in Prozent
C=95 H=97 G=95

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.22Bemerkung:  (vorverarbeitet am  2026-10-11) ¤

*Bot Zugriff






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.