pg>mysql>operators.sql
2021-09-24 15:50:04    19    0    0
ivan

mysqlcompat-0.0.7是网上开源的postgresql兼容包;

以下是写sql兼容的方式,兼容mysql函数,此种方式效率会是瓶颈;

因此尽量改成postgresql原生的函数或者底层源码兼容;

 

1 -- <=> NULL SAFE COMPARISON

-- Note: needs casts in some circumstances

CREATE OR REPLACE FUNCTION _null_safe_cmp(anyelement, anyelement)

RETURNS boolean AS '

  SELECT NOT ($1 IS DISTINCT FROM $2)

' IMMUTABLE LANGUAGE SQL;

CREATE OPERATOR <=> (

  PROCEDURE = _null_safe_cmp,

  LEFTARG = anyelement,

  RIGHTARG = anyelement

);

 

2 -- &&

-- XXX: MySQL version has wacky null behaviour

CREATE FUNCTION _and(booleanboolean)

RETURNS boolean AS $$

  SELECT $1 AND $2

$$ IMMUTABLE STRICT LANGUAGE SQL;

CREATE OPERATOR && (

  leftarg = boolean,

  rightarg = boolean,

  procedure = _and,

  commutator = &&

);

 

3 -- ||

-- XXX: MySQL version has wacky null behaviour

-- This replaces the SQL standard || concatenation operator

CREATE FUNCTION _or(booleanboolean)

RETURNS boolean AS $$

  SELECT $1 OR $2

$$ IMMUTABLE STRICT LANGUAGE SQL;

CREATE OPERATOR || (

  leftarg = boolean,

  rightarg = boolean,

  procedure = _or,

  commutator = ||

);

 

Pre: pg>mysql>mathematical.sql

Next: pg>mysql>misc.sql

19
Sign in to leave a comment.
No Leanote account? Sign up now.
0 comments
Table of content