------------------------------------------------------------
revno: 18620
committer: Bob Jolliffe <[email protected]>
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;

_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp

Reply via email to