nidus-sync/db/migrations/00076_func_gen_alpha_code.sql
Eli Ribble ff2ec0ad14
Split out ability to upload flyover data from pool uploads
Tons of changes here, all in the name of quickly getting to where I can
create test compliance letters.
2026-03-02 18:49:02 +00:00

16 lines
454 B
PL/PgSQL

-- +goose Up
-- +goose StatementBegin
CREATE OR REPLACE FUNCTION generate_alphanumeric_code(code_length INTEGER DEFAULT 8)
RETURNS TEXT AS $$
DECLARE
chars TEXT := 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
result TEXT := '';
i INTEGER;
BEGIN
FOR i IN 1..code_length LOOP
result := result || substr(chars, floor(random() * length(chars) + 1)::INTEGER, 1);
END LOOP;
RETURN result;
END;
$$ LANGUAGE plpgsql;
-- +goose StatementEnd