Postgres and ODBC: Boolean problem

Here is the solution, so I wont even forget it…

If you face a problem on your access front-end using ODBC, then here it is:

[code]
#root> ./createlang plpgsql db_name
[/code]

Once you have enabled plpgsql on that database, then we can create the functions:

[code]
DROP OPERATOR = (bool, int4);
DROP OPERATOR <> (bool, int4);
DROP FUNCTION MsAccessBool (bool, int4);
DROP FUNCTION MsAccessBoolEq (bool, int4);
DROP FUNCTION MsAccessBoolNeq (bool, int4);

CREATE FUNCTION MsAccessBoolEq (bool, int4) RETURNS BOOL AS ‘
BEGIN
IF $1 ISNULL THEN
RETURN NULL;
END IF;

IF $1 IS TRUE THEN
IF $2 <> 0 THEN
RETURN TRUE;
END IF;
ELSE
IF $2 = 0 THEN
RETURN TRUE;
END IF;
END IF;
RETURN FALSE;
END;
‘ LANGUAGE ‘plpgsql’;

CREATE FUNCTION MsAccessBoolNeq (bool, int4) RETURNS BOOL AS ‘
BEGIN
RETURN NOT MsAccessBoolEq($1, $2);
END;

‘ LANGUAGE ‘plpgsql’;

CREATE OPERATOR = (
LEFTARG = BOOL,
RIGHTARG = INT4,
PROCEDURE = MsAccessBoolEq,
COMMUTATOR = ‘=’,
NEGATOR = ‘<>‘,
RESTRICT = EQSEL,
JOIN = EQJOINSEL
);

CREATE OPERATOR <> (
LEFTARG = BOOL,
RIGHTARG = INT4,
PROCEDURE = MsAccessBoolNeq,
COMMUTATOR = ‘=’,
NEGATOR = ‘<>‘,
RESTRICT = EQSEL,
JOIN = EQJOINSEL
);
[/code]

Sphere: Related Content

Print This Post Print This Post

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)