Index: openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql,v
diff -u -r1.28 -r1.29
--- openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql	17 Aug 2002 14:29:20 -0000	1.28
+++ openacs-4/packages/acs-kernel/sql/postgresql/apm-create.sql	23 Sep 2002 11:05:17 -0000	1.29
@@ -2238,12 +2238,14 @@
 returns varchar as '
 declare
   version_name           alias for $1;  
+  a_fields               integer;       
   a_start                integer;       
   a_end                  integer;       
   a_order                varchar(1000) default ''''; 
   a_char                 char(1);       
   a_seen_letter          boolean default ''f'';        
 begin
+        a_fields := 0;
 	a_start := 1;
 	loop
 	    a_end := a_start;
@@ -2264,12 +2266,13 @@
 	    -- zero-pad and append the number
 	    a_order := a_order || substr(''0000'', 1, 4 - (a_end - a_start)) ||
 		substr(version_name, a_start, a_end - a_start) || ''.'';
+            a_fields := a_fields + 1;                                
 	    if a_end > length(version_name) then
 		-- end of string - we''re outta here
 		if a_seen_letter = ''f'' then
 		    -- append the "final" suffix if there haven''t been any letters
 		    -- so far (i.e., not development/alpha/beta)
-		    a_order := a_order || ''  3F.'';
+		    a_order := a_order || repeat(''0000.'',7 - a_fields) || ''  3F.'';
 		end if;
 		return a_order;
 	    end if;
@@ -2280,11 +2283,11 @@
 	    else
 		-- if the next character was a letter, append the appropriate characters
 		if a_char = ''d'' then
-		    a_order := a_order || ''  0D.'';
+		    a_order := a_order || repeat(''0000.'',7 - a_fields) || ''  0D.'';
 		else if a_char = ''a'' then
-		    a_order := a_order || ''  1A.'';
+		    a_order := a_order || repeat(''0000.'',7 - a_fields) || ''  1A.'';
 		else if a_char = ''b'' then
-		    a_order := a_order || ''  2B.'';
+		    a_order := a_order || repeat(''0000.'',7 - a_fields) || ''  2B.'';
 		end if; end if; end if;
     
 		-- can''t have something like 3.3a1b2 - just one letter allowed!
@@ -2305,7 +2308,6 @@
     
 end;' language 'plpgsql';
 
-
 -- function version_name_greater
 create function apm_package_version__version_name_greater (varchar,varchar)
 returns integer as '
