Index: /trunk/admin/history.php
===================================================================
--- /trunk/admin/history.php	(revision 4891)
+++ /trunk/admin/history.php	(revision 4892)
@@ -137,5 +137,5 @@
     pwg_query($query);
 
-    $search_id = pwg_db_insert_id();
+    $search_id = pwg_db_insert_id(SEARCH_TABLE);
 
     redirect(
@@ -199,5 +199,5 @@
     pwg_query($query);
 
-    $search_id = pwg_db_insert_id();
+    $search_id = pwg_db_insert_id(SEARCH_TABLE);
 
     redirect(
Index: /trunk/admin/include/functions.php
===================================================================
--- /trunk/admin/include/functions.php	(revision 4891)
+++ /trunk/admin/include/functions.php	(revision 4892)
@@ -1255,5 +1255,5 @@
     );
 
-  $inserted_id = pwg_db_insert_id();
+  $inserted_id = pwg_db_insert_id(CATEGORIES_TABLE);
 
   $query = '
@@ -1388,5 +1388,5 @@
       );
 
-    $page['tag_id_from_tag_name_cache'][$tag_name] = pwg_db_insert_id();
+    $page['tag_id_from_tag_name_cache'][$tag_name] = pwg_db_insert_id(TAGS_TABLE);
   }
   else
@@ -1663,5 +1663,5 @@
       );
 
-    $inserted_id = pwg_db_insert_id();
+    $inserted_id = pwg_db_insert_id(TAGS_TABLE);
 
     return array(
Index: /trunk/include/dblayer/functions_mysql.inc.php
===================================================================
--- /trunk/include/dblayer/functions_mysql.inc.php	(revision 4891)
+++ /trunk/include/dblayer/functions_mysql.inc.php	(revision 4892)
@@ -158,5 +158,5 @@
 }
 
-function pwg_db_insert_id()
+function pwg_db_insert_id($table=null, $column='id')
 {
   return mysql_insert_id();
Index: /trunk/include/dblayer/functions_pgsql.inc.php
===================================================================
--- /trunk/include/dblayer/functions_pgsql.inc.php	(revision 4891)
+++ /trunk/include/dblayer/functions_pgsql.inc.php	(revision 4892)
@@ -193,7 +193,13 @@
 }
 
-function pwg_db_insert_id()
-{
-  // select currval('piwigo_user_id_seq');
+function pwg_db_insert_id($table=null, $column='id')
+{
+  $sequence = sprintf('%s_%s_seq', strtolower($table), $column);
+  $query = '
+SELECT CURRVAL(\''.$sequence.'\');';
+
+  list($id) = pwg_db_fetch_row(pwg_query($query));
+
+  return $id;
 }
 
Index: /trunk/include/dblayer/functions_sqlite.inc.php
===================================================================
--- /trunk/include/dblayer/functions_sqlite.inc.php	(revision 4891)
+++ /trunk/include/dblayer/functions_sqlite.inc.php	(revision 4892)
@@ -215,5 +215,5 @@
 }
 
-function pwg_db_insert_id()
+function pwg_db_insert_id($table=null, $column='id')
 {
   global $pwg_db_link;
Index: /trunk/include/functions_comment.inc.php
===================================================================
--- /trunk/include/functions_comment.inc.php	(revision 4891)
+++ /trunk/include/functions_comment.inc.php	(revision 4892)
@@ -169,5 +169,5 @@
     pwg_query($query);
 
-    $comm['id'] = pwg_db_insert_id();
+    $comm['id'] = pwg_db_insert_id(COMMENTS_TABLE);
 
     if (($comment_action=='validate' and $conf['email_admin_on_comment']) or
Index: /trunk/include/ws_functions.inc.php
===================================================================
--- /trunk/include/ws_functions.inc.php	(revision 4891)
+++ /trunk/include/ws_functions.inc.php	(revision 4892)
@@ -1248,5 +1248,5 @@
     );
 
-  $image_id = pwg_db_insert_id();
+  $image_id = pwg_db_insert_id(IMAGES_TABLE);
 
   // let's add links between the image and the categories
Index: /trunk/qsearch.php
===================================================================
--- /trunk/qsearch.php	(revision 4891)
+++ /trunk/qsearch.php	(revision 4892)
@@ -61,5 +61,5 @@
 ;';
   pwg_query($query);
-  $search_id = pwg_db_insert_id();
+  $search_id = pwg_db_insert_id(SEARCH_TABLE);
 }
 
Index: /trunk/search.php
===================================================================
--- /trunk/search.php	(revision 4891)
+++ /trunk/search.php	(revision 4892)
@@ -149,5 +149,5 @@
     pwg_query($query);
 
-    $search_id = pwg_db_insert_id();
+    $search_id = pwg_db_insert_id(SEARCH_TABLE);
   }
   else
Index: /trunk/upload.php
===================================================================
--- /trunk/upload.php	(revision 4891)
+++ /trunk/upload.php	(revision 4892)
@@ -249,5 +249,5 @@
     $query.= ';';
     pwg_query( $query );
-    $page['waiting_id'] = pwg_db_insert_id();
+    $page['waiting_id'] = pwg_db_insert_id(WAITING_TABLE);
 
     if ($conf['email_admin_on_picture_uploaded'])
