Hi, all,
I don't like this syntax:
SELECT * FROM t1 LEFT JOIN t2 ON (t1.num = t2.num);
I prefer:
SELECT * FROM t1, t2 WHERE t1.num *= t2.num; (syntax of Sybase)
or
SELECT * FROM t1, t2 WHERE t1.num(+)= t2.num; (syntax of Oracle)
Because I have many source codes I need to port to PostgreSQL, there are many outer join in the source codes. It's a
tiredjob to rewrite the source codes using the 'LEFT JOIN ... ON' syntax. So I want to write a pair of operators '*='
and'=*' to simulate the behavior of Sybase.
I don't know how to write a join procedure. I'm not familiar with the source codes of PostgreSQL, so this mission seems
tohard for me. Who can give me some advice?
I had just started from this code.
outerjoin.sql:
CREATE FUNCTION int_left_outer_join(int, int) RETURNS bool
AS '/usr/src/postgresql-7.3.4-1/src/tutorial/outerjoin' LANGUAGE 'c';
CREATE FUNCTION int_right_outer_join(int, int) RETURNS bool
AS '/usr/src/postgresql-7.3.4-1/src/tutorial/outerjoin' LANGUAGE 'c';
CREATE OPERATOR *= (
leftarg = int,
rightarg = int,
procedure = int_left_outer_join,
join = int_left_outer_join
);
CREATE OPERATOR =* (
leftarg = int,
rightarg = int,
procedure = int_right_outer_join,
join = int_right_outer_join
);
outerjoin.c:
#include "postgres.h"
bool int_left_outer_join(int32 * a, int32 * b);
bool int_right_outer_join(int32 * a, int32 * b);
bool
int_left_outer_join(int32 * a, int32 * b)
{
return ((NULL == a) || (NULL != a && NULL != b && *a == *b));
}
bool
int_right_outer_join(int32 * a, int32 * b)
{
return ((NULL == b) || (NULL != a && NULL != b && *a == *b));
}
______________________________________
===================================================================
������ȫ������5�۷ⶥ���Żݼ��������� (http://ad4.sina.com.cn/sina/dangdang0825.html)