Re: Begin / End blocks - Mailing list pgsql-general

From Joel Burton
Subject Re: Begin / End blocks
Date
Msg-id JGEPJNMCKODMDHGOBKDNAEEICOAA.joel@joelburton.com
Whole thread Raw
In response to Begin / End blocks  ("Johnson, Shaunn" <SJohnson6@bcbsm.com>)
List pgsql-general
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).

 

BEGIN/END can refer to beginning and ending transactions (for safety, speed, etc.)

This is different from BEGIN/END as used in function. What you want is to create a function. Look in the programmer's manual under procedural languages for help using plpgsql.

pgsql-general by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: Spped of max
Next
From: Scott Marlowe
Date:
Subject: Re: Begin / End blocks