dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36380
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18620: An sql helper function to generate uids
------------------------------------------------------------
revno: 18620
committer: Bob Jolliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-03-18 18:31:01 +0000
message:
An sql helper function to generate uids
added:
resources/sql/uid.sql
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'resources/sql/uid.sql'
--- resources/sql/uid.sql 1970-01-01 00:00:00 +0000
+++ resources/sql/uid.sql 2015-03-18 18:31:01 +0000
@@ -0,0 +1,13 @@
+-- A small sql function to return a random uid
+-- suitable for use in dhis2
+
+-- Bob Jolliffe 18 March 2015
+
+CREATE OR REPLACE FUNCTION uid()
+RETURNS text AS $$
+ SELECT substring('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ FROM (random()*51)::int +1 for 1) ||
+ array_to_string(ARRAY(SELECT substring('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
+ FROM (random()*61)::int + 1 FOR 1)
+ FROM generate_series(1,10)), '')
+$$ LANGUAGE sql;