سؤال

I would like to create a function returning a table with 1 row only filled with 2 values pre-calculated.

Below my example to clarify what I mean

  create function()
  returns table(a integer,b integer)
  language sql
  begin
   declare c integer;
   declare d integer;
   set c=10;
   set d=20;
   -- how to return here c and d on the same row
   -- of a return table?
  end@

What is the best way to achieve that? Should I create a temp table and insert those 2 values or is there a special statement or special use of SELECT to do that?

هل كانت مفيدة؟

المحلول

I don't know if it's the best way, as you did not specify the criteria for being the best, but you can use the VALUES statement, like so:

create function()
returns table(a integer,b integer)
language sql
begin
 return values (10, 20);
end@

or, if you really need variables:

create function()
returns table(a integer,b integer)
language sql
begin
 declare c integer;
 declare d integer;
 set c=10;
 set d=20;
 return values (c, d);
end@
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top