Re: Performance on Bulk Insert to Partitioned Table

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Vitalii Tymchyshyn <tivv00(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Charles Gomes <charlesrg(at)outlook(dot)com>, Ondrej Ivanič <ondrej(dot)ivanic(at)gmail(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Performance on Bulk Insert to Partitioned Table
Date: 2012-12-28 14:05:17
Message-ID: CAMkU=1xcdjdFWRSZyaXyo2h8eHYz7DJRTpqeL1shMO5M858MMw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Friday, December 28, 2012, Vitalii Tymchyshyn wrote:

> There is switch-like sql case:
> 39.6.2.4. Simple CASE
>
> CASE search-expression
> WHEN expression [, expression [ ... ]] THEN
> statements
> [ WHEN expression [, expression [ ... ]] THEN
> statements
> ... ]
> [ ELSE
> statements ]
> END CASE;
>
> It should work like C switch statement.
>
>
I had thought that too, but the catch is that the target expressions do not
need to be constants when the function is created. Indeed, they can even
be volatile.

CREATE OR REPLACE FUNCTION foo(x integer)
RETURNS integer AS $$
BEGIN
case x
when 0 then return -5;
when (random()*10)::integer then return 1;
when (random()*10)::integer then return 2;
when (random()*10)::integer then return 3;
when (random()*10)::integer then return 4;
when (random()*10)::integer then return 5;
when (random()*10)::integer then return 6;
when (random()*10)::integer then return 7;
when (random()*10)::integer then return 8;
when (random()*10)::integer then return 9;
when (random()*10)::integer then return 10;
else return -6;

Cheers,

Jeff

>

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Stephen Frost 2012-12-28 14:10:29 Re: Performance on Bulk Insert to Partitioned Table
Previous Message Pavel Stehule 2012-12-28 13:41:23 Re: Performance on Bulk Insert to Partitioned Table