Click here to Skip to main content
15,889,412 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear all,

I am newbie to postgresql. I have to declare variable inside a function for internal calculation.

I am using following syntax:
Declare num1 int;

But it's giving me error:
syntax error at or near int.

Can anybody suggest me any solution?
Any kind of help is highly appreciable.

Thank you to all.
Posted
Updated 1-Mar-16 0:14am

Here is what you're looking for: PostgreSQL Documentation: Declarations[^]

The message syntax error at or near int means that int hasn't been recognized as proper data type ;) Please see: PostgreSQL documentation: Data types[^]
 
Share this answer
 
Comments
Priyanka Tiwari001 3-Sep-15 1:30am    
Hi Dear,

Thank u for your reference, it helped me to understand various other concepts. But in this documentation variable declaration syntax is:

user_id integer;
quantity numeric(5);

Its also raising error as:
syntax error at or near "integer"

In the documentation it has been mentioned that all variables should be declared in declaration section, then can you tell me what does it mean? Am I making any mistake in variable declaration? Please suggest me what should I do?

Thank u a lot...
Maciej Los 3-Sep-15 1:43am    
Each line must ends with ";"...
You can declare the variable by the following line in your procedure/function.

DECLARE variablename integer;
DECLARE variablename character varying;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900