Re: SQL Programming Question - Mailing list pgsql-general

From Darren Duncan
Subject Re: SQL Programming Question
Date
Msg-id 4C8BC866.1030702@darrenduncan.net
Whole thread Raw
In response to Re: SQL Programming Question  (Martin Gainty <mgainty@hotmail.com>)
List pgsql-general
Martin Gainty wrote:
> -- i usually
> INSERT the record
> --then check for PK VIOLATION e.g.
> IF PK_VIOLATION then UPDATE record
>
> is FoxPro still supported???

My understanding is that exception handling carries significant overhead and so
doing it within a heavy-iterated loop like this import would perform badly.
Partly for that reason and partly for code readability, I would recommend
instead the suggestion of copy the whole source to a staging table with COPY and
then use a single SQL statement to reconcile/integrate that staging table with
the main table.

In particular, I like the staging table approach because the single SQL
statement afterwards is a concise declarational code saying what you actually
want to do, relative to a client-interfacing loop which is a more verbose
imperative version.

-- Darren Duncan

pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Re: Regular expression that splits CSV string into table
Next
From: Merlin Moncure
Date:
Subject: Re: SQL Programming Question