By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Create function question...

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

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION BLAH( bigint )
  2.  declare int cnt
  3. RETURNS void as
  4. $$
  5.     cnt = select count(*) from "DCx" where "Index" = $1;
  6.     if cnt > 0
  7.     then
  8.         -- do something
  9.     end if
  10.  
  11. $$
  12. LANGUAGE sql;
  13.  
The error I get is the following...
ERROR: syntax error at or near "declare"
Jun 29 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 534
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.
Jul 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.