The function in SQL Server was written, it must be transferred to PostGre,
Gives the syntax error on the declaration of variables, tell me plz how to declare them?
create or replace function submitreview (_paper_id int, _reviewer_id int, _score int) RETURNS VOID AS $$ Begin. .... Declare @Mark Float = 0; Declare @Count int = 0; ... End; $$ Language PlpGSQL;
Answer 1, Authority 100%
it must be transferred to postgre
And why did not read Documentation ?
All Variables Used in a Block Must Be Declared in the Declarations Section of the Block.
All variables used in the block must be declared in the ad section of this unit.
create or replace function submitreview (_paper_id int, _reviewer_id int, _score int) RETURNS VOID AS $$ Declare. Mark Float; Count int; Begin. MARK: = 0; COUNT: = 0; End; $$ Language PlpGSQL;
Answer 2, Authority 100%
In PostgreSQL, the parameters of the function are not declared, only their data types are specified. Appeal is carried out by index. Also, in the Declare block, you can set named aliases to appeal in the body not by indexes, but for these alias.
and the Declaration variables are carried out in the corresponding block, and not in the body.
create or replace function submitreview (int, int, int) Returns void as $$ Declare. _paper_id alias for; _reviewer_id alias for; _score alias for; Begin. ... End; $$ Language PlpGSQL;
Although, selected, it is possible to declare them and with the names, but not necessarily. So the error is exclusively in consequences of Declare in the body.
Enclosure of Manual Create Function