0

I want to create a function in Posgresql which returns a table:

create or replace function my_func1(var1 integer, var2 integer[], var3 integer) returns table(col1 integer, col2 integer, col3 timestamp) as begin select ......... end; language sql; 

It says:

ERROR: syntax error at or near "begin" 

2 Answers 2

2

There is no begin in an SQL function. Did you mean to create a plpgsql function?

Then use LANGUAGE plpgsql instead.
And enclose the function body in quotes either way, it's text - preferably dollar quotes:

Sign up to request clarification or add additional context in comments.

9 Comments

where should I place "$func$" in the end of a function: before or after language plpgsql;?
@Torito: please see the examples in the manual. here and here and here
@a_horse_with_no_name, I don't need to.
@Torito: then why did you ask "where should I place.."? That is clearly answered in the manual.
@Torito: it is shown in the links I gave you. But if you don't want to read the manual, at least read the linked answer from Erwin. He explained in great length what that is and how to use it
|
1

Try this:

create or replace function my_func1(var1 integer, var2 integer[], var3 integer) returns table(col1 integer, col2 integer, col3 timestamp) as $func$ begin return query select ......... end; $func$ language plpgsql; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.