diff --git a/build/dolibarr_mysql2pgsql.pl b/build/dolibarr_mysql2pgsql.pl
index 3e25d553f05bccecb628f49499433c5165b86c3f..1f510ad60f1f23fe350971f094e7e67328866158 100644
--- a/build/dolibarr_mysql2pgsql.pl
+++ b/build/dolibarr_mysql2pgsql.pl
@@ -241,10 +241,14 @@ foreach my $file (keys %filelist) {
     		# nuke size of timestamp
     		s/timestamp\([^)]*\)/timestamp/i;
     
-    		# double -> real
-    		s/^double/real/i;
-    		s/(\s*)double/${1}real/i;
+    		# double -> numeric
+    		s/^double/numeric/i;
+    		s/(\s*)double/${1}numeric/i;
     
+    		# float -> numeric
+    		s/^float/numeric/i;
+    		s/(\s*)float/${1}numeric/i;
+
     		# unique key(field1,field2)
     		if (/unique key\s*\((\w+\s*,\s*\w+)\)/i) {
     		    s/unique key\s*\((\w+\s*,\s*\w+)\)/UNIQUE\($1\)/i;
diff --git a/htdocs/conf/.cvsignore b/htdocs/conf/.cvsignore
index 4573eba40aca69cf1f575425773fb30a6ac29d8a..ff44c5dfae444f5b334625cf860c0aa344d13e5d 100644
--- a/htdocs/conf/.cvsignore
+++ b/htdocs/conf/.cvsignore
@@ -1,3 +1,4 @@
 conf.php*.sav
 *.php
 conf.php.mysql
+conf.php.postgres
diff --git a/htdocs/install/mysql/migration/2.6.0-2.7.0.sql b/htdocs/install/mysql/migration/2.6.0-2.7.0.sql
index ba26cfd873b09f317c2f3a3d1119b5b239ac07e6..5b9da6624cd151812ef735c53e174025acde007c 100644
--- a/htdocs/install/mysql/migration/2.6.0-2.7.0.sql
+++ b/htdocs/install/mysql/migration/2.6.0-2.7.0.sql
@@ -449,3 +449,15 @@ INSERT INTO llx_c_departements ( code_departement, fk_region, cheflieu, tncc, nc
 INSERT INTO llx_c_departements ( code_departement, fk_region, cheflieu, tncc, ncc, nom, active) VALUES ('52', 409, '', 9, 'MELILLA', 'Melilla', 1);
 INSERT INTO llx_c_departements ( code_departement, fk_region, cheflieu, tncc, ncc, nom, active) VALUES ('53', 420, '', 20, 'OTROS', 'Otros', 1);
 
+
+alter table llx_product_price modify price_level smallint NULL DEFAULT 1;
+alter table llx_commandedet modify special_code integer UNSIGNED DEFAULT 0;
+alter table llx_facturedet modify special_code integer UNSIGNED DEFAULT 0;
+alter table llx_propaldet modify special_code integer UNSIGNED DEFAULT 0;
+alter table llx_societe modify special_code integer NULL;
+
+ALTER TABLE llx_adherent_options ADD INDEX uk_adherent_options (adhid);
+ALTER TABLE llx_bank_class ADD UNIQUE INDEX idx_bank_class_lineid (lineid);
+ALTER TABLE llx_c_ecotaxe ADD INDEX uk_c_ecotaxe (code);
+
+
diff --git a/htdocs/install/mysql/tables/llx_adherent_options.key.sql b/htdocs/install/mysql/tables/llx_adherent_options.key.sql
new file mode 100644
index 0000000000000000000000000000000000000000..4a6d53f597fe799fcbcb53ab58808227016ab30e
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_adherent_options.key.sql
@@ -0,0 +1,22 @@
+-- ===================================================================
+-- Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
+-- Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- ===================================================================
+
+ALTER TABLE llx_adherent_options ADD INDEX uk_adherent_options (adhid);
diff --git a/htdocs/install/mysql/tables/llx_adherent_options.sql b/htdocs/install/mysql/tables/llx_adherent_options.sql
index 6dc887afbae31cd22ba4660f2e61851be6825200..54bb92db3ea7361dd0529e638e194bfe81bc47b9 100644
--- a/htdocs/install/mysql/tables/llx_adherent_options.sql
+++ b/htdocs/install/mysql/tables/llx_adherent_options.sql
@@ -23,7 +23,5 @@ create table llx_adherent_options
 (
   optid            integer AUTO_INCREMENT PRIMARY KEY,
   tms              timestamp,
-  adhid            integer NOT NULL, -- id de l'adherent auquel correspond ces attributs optionnel 
-
-  UNIQUE INDEX(adhid)
+  adhid            integer NOT NULL -- id de l'adherent auquel correspond ces attributs optionnel 
 )type=innodb;
diff --git a/htdocs/install/mysql/tables/llx_bank_class.key.sql b/htdocs/install/mysql/tables/llx_bank_class.key.sql
new file mode 100644
index 0000000000000000000000000000000000000000..8d812509b93e8329383b9fdd308e10fbe2c441c4
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_bank_class.key.sql
@@ -0,0 +1,21 @@
+-- ===================================================================
+-- Copyright (C) 2004-2007 Laurent Destailleur  <eldy@users.sourceforge.net>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- ===================================================================
+
+ALTER TABLE llx_bank_class ADD UNIQUE INDEX idx_bank_class_lineid (lineid);
diff --git a/htdocs/install/mysql/tables/llx_bank_class.sql b/htdocs/install/mysql/tables/llx_bank_class.sql
index acf8fa8cf05d212ae7d89dfaed27a87f730927a4..7e5d14efe79eabb4648333959621acd819eccaf5 100644
--- a/htdocs/install/mysql/tables/llx_bank_class.sql
+++ b/htdocs/install/mysql/tables/llx_bank_class.sql
@@ -21,7 +21,5 @@
 create table llx_bank_class
 (
   lineid   integer NOT NULL,
-  fk_categ integer NOT NULL,
-
-  INDEX(lineid)
+  fk_categ integer NOT NULL
 )type=innodb;
diff --git a/htdocs/install/mysql/tables/llx_bordereau_cheque.sql b/htdocs/install/mysql/tables/llx_bordereau_cheque.sql
index 0316fe1c7ba29656b73585319a72fce7b9b4dcd3..2106b73f9e28ab19c5f3b9af9493cb00967a3f01 100644
--- a/htdocs/install/mysql/tables/llx_bordereau_cheque.sql
+++ b/htdocs/install/mysql/tables/llx_bordereau_cheque.sql
@@ -35,6 +35,6 @@ create table llx_bordereau_cheque
   fk_bank_account   integer,
   fk_user_author    integer,
   note              text,
-  statut            smallint(1) NOT NULL DEFAULT 0
+  statut            smallint NOT NULL DEFAULT 0
   
 )type=innodb;
diff --git a/htdocs/install/mysql/tables/llx_c_ecotaxe.key.sql b/htdocs/install/mysql/tables/llx_c_ecotaxe.key.sql
new file mode 100644
index 0000000000000000000000000000000000000000..211c4ad0b97d318df673de138f4073a29077737f
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_c_ecotaxe.key.sql
@@ -0,0 +1,21 @@
+-- ========================================================================
+-- Copyright (C) 2007 Regis Houssin  <regis@dolibarr.fr>
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+--
+-- $Id$
+-- ========================================================================
+
+ALTER TABLE llx_c_ecotaxe ADD INDEX uk_c_ecotaxe (code);
diff --git a/htdocs/install/mysql/tables/llx_c_ecotaxe.sql b/htdocs/install/mysql/tables/llx_c_ecotaxe.sql
index a2f9eb733736ebbfb164e0816db509d61d4e0dae..c71f6ecbf48e3aa9bf3a5146047fb860442fd499 100644
--- a/htdocs/install/mysql/tables/llx_c_ecotaxe.sql
+++ b/htdocs/install/mysql/tables/llx_c_ecotaxe.sql
@@ -1,5 +1,5 @@
 -- ========================================================================
--- Copyright (C) 2007 R�gis Houssin  <regis@dolibarr.fr>
+-- Copyright (C) 2007 R�gis Houssin  <regis@dolibarr.fr>
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -21,10 +21,10 @@
 create table llx_c_ecotaxe
 (
   rowid        integer      AUTO_INCREMENT PRIMARY KEY,
-  code         varchar(64)  UNIQUE NOT NULL,  -- Code servant � la traduction et � la r�f�rence interne
-  libelle      varchar(255),                  -- Description
-  price        double(24,8),                  -- Montant HT
-  organization varchar(255),                  -- Organisme g�rant le bar�me tarifaire
-  fk_pays      integer NOT NULL,              -- Pays correspondant
+  code         varchar(64)  NOT NULL,  		-- Code servant a la traduction et a la reference interne
+  libelle      varchar(255),                -- Description
+  price        double(24,8),                -- Montant HT
+  organization varchar(255),                -- Organisme gerant le bareme tarifaire
+  fk_pays      integer NOT NULL,            -- Pays correspondant
   active       tinyint DEFAULT 1  NOT NULL
 )type=innodb;
\ No newline at end of file
diff --git a/htdocs/install/mysql/tables/llx_commandedet.sql b/htdocs/install/mysql/tables/llx_commandedet.sql
index d5e0379bcae2fd8f741e9a2f609df1929ebbdb7d..176b973c9eba2ad27799b6ef05253224316fad4d 100644
--- a/htdocs/install/mysql/tables/llx_commandedet.sql
+++ b/htdocs/install/mysql/tables/llx_commandedet.sql
@@ -41,7 +41,7 @@ create table llx_commandedet
   info_bits          integer      DEFAULT 0,          -- TVA NPR ou non
   marge_tx           double(6,3)  DEFAULT 0,          -- taux de marge (marge sur prix d'achat)
   marque_tx          double(6,3)  DEFAULT 0,          -- taux de marque (marge sur prix de vente)
-  special_code       tinyint(4)   UNSIGNED DEFAULT 0, -- code pour les lignes speciales
+  special_code       integer UNSIGNED DEFAULT 0,      -- code pour les lignes speciales
   rang               integer      DEFAULT 0,
   import_key         varchar(14)
 )type=innodb;
diff --git a/htdocs/install/mysql/tables/llx_facturedet.sql b/htdocs/install/mysql/tables/llx_facturedet.sql
index 2157c5b496ed6889ba7aea5660a40d49956238f8..2a75d2f4547aa612877fe115968004c7d57532fb 100644
--- a/htdocs/install/mysql/tables/llx_facturedet.sql
+++ b/htdocs/install/mysql/tables/llx_facturedet.sql
@@ -42,7 +42,7 @@ create table llx_facturedet
   info_bits		      integer    DEFAULT 0, 	       -- TVA NPR ou non
   fk_code_ventilation integer    DEFAULT 0 NOT NULL,
   fk_export_compta    integer    DEFAULT 0 NOT NULL,
-  special_code        tinyint(4) UNSIGNED DEFAULT 0, -- code pour les lignes speciales
+  special_code        integer UNSIGNED DEFAULT 0,    -- code pour les lignes speciales
   rang                integer    DEFAULT 0,          -- ordre d'affichage
   import_key          varchar(14)
 )type=innodb;
diff --git a/htdocs/install/mysql/tables/llx_menu.sql b/htdocs/install/mysql/tables/llx_menu.sql
index e979eda4ccf3b88cd9319efb00885c667f4d5413..613c357e208a3ae21f1b9de3420b31b0cb66c711 100644
--- a/htdocs/install/mysql/tables/llx_menu.sql
+++ b/htdocs/install/mysql/tables/llx_menu.sql
@@ -35,7 +35,7 @@ CREATE TABLE llx_menu
 	target        varchar(100) NULL,                -- Target of Url link
 	titre         varchar(255) NOT NULL,            -- Key for menu translation 
 	langs         varchar(100),                     -- Lang file to load for translation
-	level         tinyint(1),                       -- Used by auguria menu only. Do not use.
+	level         smallint,                         -- Used by auguria menu only. Do not use.
 	leftmenu      varchar(1) NULL default '1',      -- Say if left menu defined in pre.inc.php and used by top menu must be overwritten by dynamic databse menu (1=yes by default)
 	perms         varchar(255),                     -- Condition to show enabled or disabled
 	enabled       varchar(255) NULL default '1',    -- Condition to show or hide
diff --git a/htdocs/install/mysql/tables/llx_paiementfourn.sql b/htdocs/install/mysql/tables/llx_paiementfourn.sql
index e94dc073152cc743b61e90f23951fc694aad7650..dc0891ba2097e2fbdba1bc4192f27656656f39b2 100644
--- a/htdocs/install/mysql/tables/llx_paiementfourn.sql
+++ b/htdocs/install/mysql/tables/llx_paiementfourn.sql
@@ -29,8 +29,8 @@ create table llx_paiementfourn
   amount            real DEFAULT 0,    -- montant
   fk_user_author    integer,           -- auteur
   fk_paiement       integer NOT NULL,  -- moyen de paiement
-  num_paiement      varchar(50),       -- num�ro de paiement (cheque)
+  num_paiement      varchar(50),       -- num�ro de paiement (cheque)
   note              text,
   fk_bank           integer NOT NULL,
-  statut			smallint(6) NOT NULL DEFAULT 0
+  statut			smallint NOT NULL DEFAULT 0
 )type=innodb;
diff --git a/htdocs/install/mysql/tables/llx_product_price.sql b/htdocs/install/mysql/tables/llx_product_price.sql
index 1cf392edf7f614908651131966f7784617717372..324bf0dadbb66c1312116b83d5e3948a5bbfb44d 100644
--- a/htdocs/install/mysql/tables/llx_product_price.sql
+++ b/htdocs/install/mysql/tables/llx_product_price.sql
@@ -24,7 +24,7 @@ create table llx_product_price
   tms             timestamp,
   fk_product      integer NOT NULL,
   date_price      datetime NOT NULL,
-  price_level	    tinyint(4) NULL DEFAULT 1,
+  price_level	    smallint NULL DEFAULT 1,
   price           double(24,8) DEFAULT NULL,
   price_ttc       double(24,8) DEFAULT NULL,
   price_min              double(24,8) default NULL,
diff --git a/htdocs/install/mysql/tables/llx_propaldet.sql b/htdocs/install/mysql/tables/llx_propaldet.sql
index 05d90bddded93415e3bead2bbfd7007e22d7cc7a..f218c7f07b02a3c3f5e3294f1ea19822afd050bc 100644
--- a/htdocs/install/mysql/tables/llx_propaldet.sql
+++ b/htdocs/install/mysql/tables/llx_propaldet.sql
@@ -31,9 +31,9 @@ create table llx_propaldet
   remise            real         DEFAULT 0,          -- montant de la remise (obsolete)
   price             real,                            -- prix final (obsolete)
   subprice          double(24,8) DEFAULT 0,          -- prix unitaire article
-  total_ht          double(24,8) DEFAULT 0,          -- Total HT de la ligne toute quantit� et incluant remise ligne et globale
-  total_tva         double(24,8) DEFAULT 0,          -- Total TVA de la ligne toute quantit� et incluant remise ligne et globale
-  total_ttc         double(24,8) DEFAULT 0,          -- Total TTC de la ligne toute quantit� et incluant remise ligne et globale
+  total_ht          double(24,8) DEFAULT 0,          -- Total HT de la ligne toute quantit� et incluant remise ligne et globale
+  total_tva         double(24,8) DEFAULT 0,          -- Total TVA de la ligne toute quantit� et incluant remise ligne et globale
+  total_ttc         double(24,8) DEFAULT 0,          -- Total TTC de la ligne toute quantit� et incluant remise ligne et globale
   product_type		  integer    DEFAULT 0,
   date_start          datetime   DEFAULT NULL,       -- date debut si service
   date_end            datetime   DEFAULT NULL,       -- date fin si service
@@ -43,7 +43,7 @@ create table llx_propaldet
   marge_tx          double(6,3)  DEFAULT 0,          -- taux de marge (marge sur prix d'achat)
   marque_tx         double(6,3)  DEFAULT 0,          -- taux de marque (marge sur prix de vente)
 
-  special_code      tinyint(4)   UNSIGNED DEFAULT 0, -- code pour les lignes speciales
+  special_code      integer UNSIGNED DEFAULT 0,      -- code pour les lignes speciales
   rang              integer      DEFAULT 0           -- ordre affichage sur la propal
 )type=innodb;
 
diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql
index 043949b5eaea80c307fc3893cac0fd2fbc8b0942..cbf9f9c21402d23b3370132c4c57d5ae131b0c1e 100644
--- a/htdocs/install/mysql/tables/llx_societe.sql
+++ b/htdocs/install/mysql/tables/llx_societe.sql
@@ -52,7 +52,7 @@ create table llx_societe
   ape                      varchar(16),                         -- IDProf3: code ape pour france
   idprof4                  varchar(16),                         -- IDProf4: nu pour france
   tva_intra                varchar(20),                         -- tva
-  capital                  real,                                -- capital de la soci�t�
+  capital                  real,                                -- capital de la soci�t�
   description              text,                                --
   fk_stcomm                smallint       DEFAULT 0,            -- commercial statut
   note                     text,                                --
@@ -63,16 +63,16 @@ create table llx_societe
   supplier_account         varchar(32),                         -- compte client chez un fournisseur
   fk_prospectlevel         varchar(12),                         -- prospect level (in llx_c_prospectlevel)
   customer_bad             tinyint        DEFAULT 0,            -- mauvais payeur 0/1
-  customer_rate            real           DEFAULT 0,            -- taux fiabili� client (0 � 1)
-  supplier_rate            real           DEFAULT 0,            -- taux fiabili� fournisseur (0 � 1)
-  fk_user_creat            integer NULL,                        -- utilisateur qui a cr�� l'info
-  fk_user_modif            integer,                             -- utilisateur qui a modifi� l'info
-  remise_client            real           DEFAULT 0,            -- remise syst�matique pour le client
-  mode_reglement           tinyint,                             -- mode de r�glement
-  cond_reglement           tinyint,                             -- condition de r�glement
-  tva_assuj                tinyint        DEFAULT 1,	        -- assujeti ou non � la TVA
+  customer_rate            real           DEFAULT 0,            -- taux fiabili� client (0 � 1)
+  supplier_rate            real           DEFAULT 0,            -- taux fiabili� fournisseur (0 � 1)
+  fk_user_creat            integer NULL,                        -- utilisateur qui a cr�� l'info
+  fk_user_modif            integer,                             -- utilisateur qui a modifi� l'info
+  remise_client            real           DEFAULT 0,            -- remise syst�matique pour le client
+  mode_reglement           tinyint,                             -- mode de r�glement
+  cond_reglement           tinyint,                             -- condition de r�glement
+  tva_assuj                tinyint        DEFAULT 1,	        -- assujeti ou non � la TVA
   gencod                   varchar(255),                        -- barcode
-  price_level              tinyint(4) NULL,                     -- level of price for multiprices
+  price_level              integer NULL,                        -- level of price for multiprices
   import_key               varchar(14)                          -- import key
 )type=innodb;
 
diff --git a/htdocs/install/mysql/tables/llx_user_entrepot.sql b/htdocs/install/mysql/tables/llx_user_entrepot.sql
index 22496e3393da28cb7078a92dac45b3755a2bc2d2..a9eb820102b77f5f3c55017dc5d10729fbf1096e 100644
--- a/htdocs/install/mysql/tables/llx_user_entrepot.sql
+++ b/htdocs/install/mysql/tables/llx_user_entrepot.sql
@@ -23,6 +23,6 @@ create table llx_user_entrepot
   rowid        integer AUTO_INCREMENT PRIMARY KEY,
   fk_entrepot  integer UNSIGNED, -- pointe sur llx_entrepot
   fk_user      integer UNSIGNED, -- pointe sur llx_user
-  consult      tinyint(1) UNSIGNED,
-  send         tinyint(1) UNSIGNED
+  consult      smallint UNSIGNED,
+  send         smallint UNSIGNED
 )type=innodb;
diff --git a/htdocs/lib/databases/mssql.lib.php b/htdocs/lib/databases/mssql.lib.php
index e7b7503066cf68c2dec1f942974a7e07d50098ce..6c4757ef57a947d53e4c687bcd99ba3a3c3dbbe7 100644
--- a/htdocs/lib/databases/mssql.lib.php
+++ b/htdocs/lib/databases/mssql.lib.php
@@ -297,9 +297,9 @@ class DoliDb
 	}
 
 	/**
-	 \brief      Effectue une requete et renvoi le resultset de reponse de la base
-	 \param	    query	    Contenu de la query
-	 \return	    resource    Resultset de la reponse
+	 *	\brief      Effectue une requete et renvoi le resultset de reponse de la base
+	 *	\param	    query	    Contenu de la query
+	 *	\return	    resource    Resultset de la reponse
 	 */
 	function query($query)
 	{
diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php
index ca03c4471d475156beed5152fdfd53c40a44a16e..8b3e736550c9bd530d77e9d77df321dec52ce990 100644
--- a/htdocs/lib/databases/pgsql.lib.php
+++ b/htdocs/lib/databases/pgsql.lib.php
@@ -214,11 +214,14 @@ class DoliDb
 			$line=preg_replace('/datetime/i','timestamp',$line);
 
 			# nuke size of timestamp
-			//    		s/timestamp\([^)]*\)/timestamp/i;
+    		$line=preg_replace('/timestamp\([^)]*\)/i','timestamp',$line);
 
-			# double -> real
-			//    		s/^double/real/i;
-			//    		s/(\s*)double/${1}real/i;
+			# double -> numeric
+    		$line=preg_replace('/^double/i','numeric',$line);
+    		$line=preg_replace('/(\s*)double/i','\\1numeric',$line);
+			# float -> numeric
+    		$line=preg_replace('/^float/i','numeric',$line);
+    		$line=preg_replace('/(\s*)float/i','\\1numeric',$line);
 
 			# unique key(field1,field2)
 			/*    		if (/unique key\s*\((\w+\s*,\s*\w+)\)/i) {
@@ -228,12 +231,10 @@ class DoliDb
 			}
 			*/
 			# unique index(field1,field2)
-			/*    		if (/unique index\s*\((\w+\s*,\s*\w+)\)/i) {
-			s/unique index\s*\((\w+\s*,\s*\w+)\)/UNIQUE\($1\)/i;
-			$create_sql.=$_;
-			next;
+			if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line))
+			{
+				$line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line);
 			}
-			*/
 			# unique key [name] (field)
 			/*            if (/unique key\s*(\w*)\s*\((\w+)\)/i) {
 			s/unique key\s*(\w*)\s*\((\w+)\)/UNIQUE\($2\)/i;
@@ -492,7 +493,7 @@ class DoliDb
 		// Convert MySQL syntax to PostgresSQL syntax
 		$query=$this->convertSQLFromMysql($query);
 
-		$ret = pg_query($this->db, $query);
+		$ret = @pg_query($this->db, $query);
 		if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query))
 		{
 			// Si requete utilisateur, on la sauvegarde ainsi que son resultset
@@ -501,7 +502,8 @@ class DoliDb
 				$this->lastqueryerror = $query;
 				$this->lasterror = $this->error();
 				$this->lasterrno = $this->errno();
-				print '>>'.$this->lasterrno.' - '.$this->lasterror.' - '.$this->laqtqueryerror."<br>\n";
+				//print "\n>> ".$query."<br>\n";
+				//print '>> '.$this->lasterrno.' - '.$this->lasterror.' - '.$this->laqtqueryerror."<br>\n";
 			}
 			$this->lastquery=$query;
 			$this->results = $ret;
@@ -758,7 +760,8 @@ class DoliDb
 			1060 => 'DB_ERROR_COLUMN_ALREADY_EXISTS',
 			1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
 			1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS',
-			1064 => 'DB_ERROR_SYNTAX',
+			'42704' => 'DB_ERROR_SYNTAX',
+			'42601' => 'DB_ERROR_SYNTAX',
 			1068 => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
 			1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY',
 			1091 => 'DB_ERROR_NOSUCHFIELD',
@@ -775,13 +778,12 @@ class DoliDb
 			if (preg_match('/: *([0-9P]+):/',$errorlabel,$reg))
 			{
 				$errorcode=$reg[1];
+				if (isset($errorcode_map[$errorcode]))
+				{
+					return $errorcode_map[$errorcode];
+				}
 			}
-
-			if (isset($errorcode_map[$errorcode]))
-			{
-				return $errorcode_map[$errorcode];
-			}
-			$errno=$errorlabel;
+			$errno=$errorcode?$errorcode:$errorlabel;
 			return ($errno?'DB_ERROR_'.$errno:'0');
 		}
 
diff --git a/htdocs/lib/functions2.lib.php b/htdocs/lib/functions2.lib.php
index 213bd4a16ddfabbc8f4458d18d04abc8d6fa93b5..a45b28fa1ebade9eaa0fc7b67a0458400be158ba 100644
--- a/htdocs/lib/functions2.lib.php
+++ b/htdocs/lib/functions2.lib.php
@@ -240,7 +240,7 @@ function isValidUrl($url,$http=0,$pass=0,$port=0,$path=0,$query=0,$anchor=0)
 	$urlregex = '';
 
 	// SCHEME
-	if ($http) $urlregex .= "/^(http:\/\/|https:\/\/)";
+	if ($http) $urlregex .= "^(http:\/\/|https:\/\/)";
 
 	// USER AND PASS
 	if ($pass) $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)";
@@ -258,10 +258,10 @@ function isValidUrl($url,$http=0,$pass=0,$port=0,$path=0,$query=0,$anchor=0)
 	// GET Query
 	if ($query) $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)";
 	// ANCHOR
-	if($anchor) $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)$/i";
+	if ($anchor) $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)$/i";
 
 	// check
-	if (preg_match($urlregex, $url))
+	if (preg_match('!'.$urlregex.'!', $url))
 	{
 		$ValidUrl = 1;
 	}
@@ -300,7 +300,7 @@ function clean_url($url,$http=1)
 				$newproto = '';
 			}
 		}
-		
+
 		// On passe le nom de domaine en minuscule
 		$CleanUrl = preg_replace('/^'.preg_quote($proto.$domain,'/').'/i', $newproto.strtolower($domain), $url);