Sha256: 0a89dbf8661d7ef11fb6765c4e3d9903da5726ee1a905200fc0cd454f6c979fa

Contents?: true

Size: 617 Bytes

Versions: 143

Compression:

Stored size: 617 Bytes

Contents

CREATE OR REPLACE FUNCTION generate_secure_id(length integer default 24)
  /*
  Generates and returns a unique base 58 token of <length> length for use in for example
  the obfuscation of database ids in URLs.
  Note base58 tokens are case sensitive.
  Example usage:
    select generate_secure_id(24) #=> 0KPNXf4X5x1o6O4mXWE5MC9H
  TC 8.6.2017
  */
  RETURNS text AS
  $body$
  SELECT string_agg (substr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
                     ceil (random() * 62)::integer,
                     1), '')
  FROM   generate_series(1, length)
  ;
  $body$
  LANGUAGE sql;

Version data entries

143 entries across 143 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc11 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.0.pre.rc10 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.0.pre.rc9 db/functions/generate_secure_id_v01.sql