Received: from primaire.intelcom.fr (primaire.intelcom.fr [194.250.33.1]) by hub.org (8.10.1/8.10.1) with ESMTP id e7HDNJm49891 for ; Thu, 17 Aug 2000 09:23:20 -0400 (EDT) Received: from volvo.intelcom.fr ([192.168.160.20]) by primaire.intelcom.fr (8.8.8+Sun/8.8.8) with SMTP id PAA19141 for ; Thu, 17 Aug 2000 15:23:11 +0200 (MET DST) Received: from intelcom.fr by volvo.intelcom.fr (SMI-8.6/SMI-SVR4) id PAA18243; Thu, 17 Aug 2000 15:23:12 +0200 Message-ID: <399BE740.C0664D1E@intelcom.fr> Date: Thu, 17 Aug 2000 15:23:12 +0200 From: Jerome Raupach X-Mailer: Mozilla 4.74 [en] (X11; U; SunOS 5.5 sun4d) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: optimization in C Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200008/155 This solution isn't good when there are +10000 tuples in the table, it's slowly... anybody can help me ? : string = "SELECT service, noeud, rubrique FROM table" ; res = PQexec( conn, string.data() ) ; if ( (! res) || (status = PQresultStatus( res ) != PGRES_TUPLES_OK) ) { cerr << _ERROR << "Problem SELECT ! " << endl ; cerr << _ERROR << "Error : " << PQresStatus( status ) << endl ; cerr << _ERROR << "Error : " << PQresultErrorMessage( res ) << endl ; PQclear( res ) ; } else { for (int m=0; m < PQntuples( res ); m++) { service = PQgetvalue( resultat1, m, 0 ) ; noeud = PQgetvalue( resultat1, m, 1 ) ; rubrique = PQgetvalue( resultat1, m, 2 ) ; commande = "SELECT SUM(date) FROM table WHERE service='" + service + "' AND noeud='" + noeud + "' AND rubrique='"+ rubrique + "'" ; res1 = PQexec( conn, string.data() ) ; if ( (! res1) || (status = PQresultStatus( res1 ) != PGRES_TUPLES_OK) ) { cerr << _ERROR << "Problem SUM ! " << endl ; cerr << _ERROR << "Error : " << PQresStatus( status ) << endl ; cerr << _ERROR << "Error : " << PQresultErrorMessage( res1 ) << endl ; PQclear( res1 ) ; } else { cout << _TRACE << "SUM ok." << endl ; PQclear( res1 ) ; } } PQclear( res ) ; } Thanks. jerome.