Re: pg_query and COPY in transaction

From: Date: Wed, 19 Jul 2006 13:59:41 +0000
Subject: Re: pg_query and COPY in transaction
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-239572@lists.php.net to get a copy of this message
Luis Magaña wrote: > I have the following code: > > pg_query($conn,"BEGIN TRANSACTION; > DELETE FROM codigo_postal; > COPY > codigo_postal(codigo_postal,asentamiento,tipo_asentamiento,municipio,estado) > FROM '$tmpfname2' DELIMITER '|'; > COMMIT"); > > It is suppoused as I understand it, that if an error occurs on the copy > statement, then the codigo_postal table should still have all of the > previous records. Actually I've tested it within psql and it works as > expected. > > However, the shown code does not. If an error occurs on the copy > transaction, the data on the table gets deleted. > The above code looks like it should work. I have done similar stuff in the past. A useful trick that you might like to try is that PHP automatically will automatically wrap a query with multiple parts into a transaction for you. I believe it will also do slightly more advanced clean up of the commit/rollback than the default. Doing it this way might work better for you. David

« previous php.general (#239572) next »