Re: Begin / End blocks

Поиск
Список
Период
Сортировка
Искать
От
Darren Ferguson
Тема
Re: Begin / End blocks
Дата
в 17:56:07
Msg-id
Pine.LNX.4.10.10205141736040.7360-100000@thread.crystalballinc.com
Ответ на
Begin / End blocks (Johnson, Shaunn)
Список
Дерево обсуждения
Begin / End blocks "Johnson, Shaunn" <SJohnson6@bcbsm.com>
Re: Begin / End blocks "Joel Burton" <joel@joelburton.com>
Re: Begin / End blocks Darren Ferguson <darren@crystalballinc.com>
Re: Begin / End blocks Scott Marlowe <scott.marlowe@ihs.com>
You can make it a function but you can also do

BEGIN;

SELECT CASE WHEN (SELECT SUM(*) FROM table) < 1500
                 THEN (INSERT INTO new_table (SELECT * FROM table))
            ELSE ''f'' END AS test;
END;

I have not tested it but it should work.

HTH

Darren Ferguson

On Tue, 14 May 2002, Johnson, Shaunn wrote:

> Howdy:
> 
> Running Postgres 7.1.3 on RedHat Linux 2.4.7-rel 10.
> 
> I'm trying to learn how to use the BEGIN / END
> blocks.  My goal is to test the count
> of a table and do such and such from there.
> 
> [pseudo code]
> 
> begin 
> 	if 
> 		select sum (*) from table < 1500
> 	then
> 		select into new_table * from table
> 	else
> 		return ''f'';
> 	end if;
> end
> 
> [/code]
> 
> questions:
> 
> * Do I have to make this a function?  
> 
> * Is there a way to assign the value of
> the count (or, sum of records in table) 
> to a variable and test for -that- ?
> 
> * I'm looking at the postgresql.org site
> for examples, but all of the BEGIN / END
> blocks are within creating a function - I'm
> not sure I want to create one ...
> 
> * I'm sure the code above is wrong
> (especially with the if statement) - 
> where can I find better code (groups.
> google.com isn't working well, either).
> 
> Thanks!
> 
> -X
> 

В списке pgsql-general по дате отправления
От: Scott Marlowe
Дата:
Сообщение: Re: Begin / End blocks
От: Joel Burton
Дата:
Сообщение: Re: Using COPY
FAQ