CRC32 problem in RONIN heroku database

Alejandro Andrés's Avatar

Alejandro Andrés

10 Feb, 2012 09:18 AM

Hi! We have upgraded recently to a Ronin database and everything was working perfectly. But adding a CRC32 attribute to the index is giving some problems:

[RED] ERROR:  function crc32(character varying) does not exist at character 369
[RED] HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

I don't know hot to proceed becase the indexed attribute has too many options to discriminate with a case, and we would really like to use CRC32. Is there a way I could provide our database (not sahred!) with the proper function?

Thanks!

  1. 1 Posted by Alejandro André... on 10 Feb, 2012 09:56 AM

    Alejandro Andrés's Avatar

    Ok, I'm a fast asker and a slow researcher :D
    I solved this by manually injecting the CRC32 function code from Thinking Sphinx into our DB:

    CREATE OR REPLACE FUNCTION crc32(word text)
    RETURNS bigint AS $$
    DECLARE tmp bigint;
    DECLARE i int;
    DECLARE j int;
    DECLARE byte_length int;
    DECLARE word_array bytea;
    BEGIN
    IF COALESCE(word, '') = '' THEN
    return 0;
    END IF;
    
    i = 0;
    tmp = 4294967295;
    byte_length = bit_length(word) / 8;
    word_array = decode(replace(word, E'\\\\', E'\\\\\\\\'), 'escape');
    LOOP
    tmp = (tmp # get_byte(word_array, i))::bigint;
    i = i + 1;
    j = 0;
    LOOP
    tmp = ((tmp >> 1) # (3988292384 * (tmp & 1)))::bigint;
    j = j + 1;
    IF j >= 8 THEN
    EXIT;
    END IF;
    END LOOP;
    IF i >= byte_length THEN
    EXIT;
    END IF;
    END LOOP;
    return (tmp # 4294967295);
    END
    $$ IMMUTABLE LANGUAGE plpgsql;
    

    Thank you again Pat for this awesome project! :D

  2. 2 Posted by james on 12 Feb, 2012 09:57 AM

    james's Avatar

    Sorry for the slow response, luckily adding the function yourself would've been my recommendation.

    The regular thinking-sphinx gem creates the function for you, however it's disabled in flying-sphinx because of the shared database issue.

  3. Pat Allan closed this discussion on 13 Jan, 2014 11:27 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac