From: | Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: “Loop” in plpgsql Function - PostgreSQL 9.2 |
Date: | 2016-01-19 08:45:24 |
Message-ID: | 871t9enejf.fsf@hf.protecting.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com> writes:
> So, the new plan is:
>
> 1 - Select 50.000 rows and gives it a batch number.
> 2 - Select *MORE* 50,000 rows and gives it a *NEW* batch number.
> 3 - Select *MORE* 50,000 rows and gives it a *NEW* batch number.
Why so complicated? Here's a simplified example:
CREATE TABLE mytable (
id serial NOT NULL,
payload int NOT NULL,
batch_number int NULL,
PRIMARY KEY (id)
);
INSERT INTO mytable (payload)
SELECT x FROM generate_series(1, 2000) AS g(x);
\set batchSize 600
UPDATE mytable
SET batch_number = (id % (SELECT count(*) FROM mytable) / :batchSize) + 1;
SELECT batch_number, count(*) AS cnt
FROM mytable
GROUP BY batch_number
ORDER BY batch_number;
From | Date | Subject | |
---|---|---|---|
Next Message | mariusz | 2016-01-19 09:39:45 | Re: “Loop” in plpgsql Function - PostgreSQL 9.2 |
Previous Message | DerekW | 2016-01-19 07:40:50 | Re: Error installing 9.5 on Win 2012 R2: data dir not created |