Created
December 4, 2014 02:04
-
-
Save brhoades/d9f909c29b1461da7bb8 to your computer and use it in GitHub Desktop.
Returns a probability distribution of words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION somefuncname() RETURNS int LANGUAGE plpgsql AS $$ | |
DECLARE | |
tmp int; | |
BEGIN | |
CREATE TEMP TABLE res AS SELECT id, SUM(count) OVER (ORDER BY id DESC) AS cum_sum FROM chains WHERE wid=## GROUP BY id ORDER BY cum_sum DESC; | |
tmp := FLOOR(random()*( SELECT max(cum_sum) FROM res LIMIT 1 )); | |
RETURN (SELECT cum_sum FROM res WHERE cum_sum > tmp ORDER BY cum_sum ASC LIMIT 1 ); | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment