1. Weighted Random Sampling with PostgreSQL

    You have a table like the following:

    CREATE TABLE weights (
    color varchar primary key,
    weight float
    INSERT INTO weights (color, weight)
    ('red', 8),
    ('blue', 3),
    ('green', 10),
    ('yellow', 10);

    The table lists the weights associated with certain colors. Imagine a weight representing how much you like that color.

    Now …

    read more

« Page 2 / 3 »