Marco Molinaro molinaro at
Wed Jul 6 10:49:05 CEST 2016

Hi again,
reporting Ger's comment on the  MOD function

2016-07-05 21:25 GMT+02:00 Ger van Diepen <diepen at>:
> Maybe it should be described what the remainder is in case x and/or y is
> negative.
> E.g.: x%y gives different results in C and Python for negative numbers.
> Cheers,
> Ger

I indeed think it is (R)DBMS implementation dependent, maybe one more
point to check with Dave's Cosmopterix.

A quick search in the SQL standard discussions online seems to point out
that A%B=R is valid with R having the same sign as A and ABS(R) being
smaller than ABS(B), plus the counter check that A=B*K+R where K is some
integer value (out of A/B).

Maybe we are lucky and all the RDBMSs we're interested in act this way.

I'm not sure, however, that forcing this thing into the standard would be
useful. Probably alerting the ADQL users might be enough.


>>>> Marco Molinaro <molinaro at> 07/05/16 3:32 PM >>>
> Dear Mark, DAL,
> I think this is an erratum, with x and y switched in the description.
> Cheers,
> Marco
> 2016-07-05 15:25 GMT+02:00 Mark Taylor <M.B.Taylor at>:
>> Dear DAL,
>> table 1 of REC-ADQL-2.0 defines the MOD function thus:
>> Name Arg type Return type Description
>> --------- -------- ----------- -----------
>> mod(x, y) double double Returns the remainder of y/x.
>> but as far as I can see, SQL 2003 (I presume 92 as well) and all
>> the TAP services that I generally use define the arguments the other
>> way around, i.e. returning the remainder of x/y.
>> Am I misreading something or is this an erratum candidate?
>> Mark
>> --
>> Mark Taylor Astronomical Programmer Physics, Bristol University, UK
>> m.b.taylor at +44-117-9288776

More information about the dal mailing list