Re: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking? - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking?
Date
Msg-id 46D3A31F-F2CC-4014-8FE6-9040A077E792@solfertje.student.utwente.nl
Whole thread Raw
In response to Re: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking?  (Craig Ringer <craig@postnewspapers.com.au>)
List pgsql-general
On May 3, 2009, at 9:00 AM, Craig Ringer wrote:

> CREATE OR REPLACE FUNCTION luhn_verify(int8) RETURNS boolean AS $$
> SELECT
>    -- Add the digits, doubling odd-numbered digits (counting left with
>    -- least significant as zero), and see if the sum is evenly
>    -- divisible by zero.

I think you mean divisible by 10 here, numbers are generally not
divisible by zero ;)

Regardless, thanks for posting these functions, I'm sure they'll come
in handy some time.

>
>    MOD(SUM(
>       -- Extract digit `n' counting left from least significant as
> zero
>       MOD( ( $1::int8 / (10^n)::int8 ), 10::int8)
>       -- Double odd-numbered digits
>       * (MOD(n,2) + 1)
>    ), 10) = 0
> FROM generate_series(0, ceil(log( $1 ))::integer - 1) AS n;
> $$ LANGUAGE 'SQL'
> IMMUTABLE
> STRICT;
>
> COMMENT ON FUNCTION luhn_verify(int8) IS 'Return true iff the last
> digit
> of the input is a correct check digit for the rest of the input
> according to Luhn''s algorithm.'

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,49fd82b6129742129210600!



pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Re: Mapping output from a SEQUENCE into something non-repeating/colliding but random-looking?
Next
From: garry@schoolteachers.co.uk
Date:
Subject: windows service