Re: Function with limit and offset - PostgreSQL 9.3

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Function with limit and offset - PostgreSQL 9.3
Date: 2017-06-09 01:13:26
Message-ID: b17667ab-7743-0edf-089a-ac103f09096e@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6/8/2017 5:53 PM, marcinha rocha wrote:
> Hi guys! I have the following queries, which will basically select
> data, insert it onto a new table and update a column on the original
> table.

I'm sure your example is a gross simplification of what you're really
doing, but if that's really all you're doing, why not do it all at once,
instead of row at a time?

BEGIN;
insert into tableb (id) select id from tablea;
update tablea set migrated=true;
COMMIT;

thats far more efficient that the row-at-a-time iterative solution you
showed.

--
john r pierce, recycling bits in santa cruz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2017-06-09 01:34:01 Re: How does BDR replicate changes among nodes in a BDR group
Previous Message David G. Johnston 2017-06-09 01:05:47 Re: Function with limit and offset - PostgreSQL 9.3