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.149 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.148 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.147 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.146 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.145 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.144 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.143 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.142 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.141 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.140 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.139 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.138 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.137 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.136 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.135 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.134 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.133 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.132 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.131 db/functions/generate_secure_id_v01.sql
renalware-core-2.0.130 db/functions/generate_secure_id_v01.sql