Create function question...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • UngaWunga
    New Member
    • Jun 2007
    • 4

    #1

    Create function question...

    Ok, my syntax is off somewhere. Can someone set me straight on how to declare a local variable in a function?

    Code:
    CREATE OR REPLACE FUNCTION BLAH( bigint )
     declare int cnt
    RETURNS void as
    $$
    	cnt = select count(*) from "DCx" where "Index" = $1;
    	if cnt > 0
    	then
    		-- do something
    	end if
    
    $$
    LANGUAGE sql;
    The error I get is the following...
    ERROR: syntax error at or near "declare"
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    Looks like the variable declaration is misplaced (among other problems)...

    Just take a look at the manual.
    create function
    sql function
    plpgsql
    Declarations in plpgsql functions

    Let us know if you still have any questions or problems with your code.

    Comment

    Working...