Imagine what I want here that I have a table with the line A .
I have to:
SELECT A, from func (A) table, and say 4 columns for output .
Is there any way to do this? I have seen things of a custom type or whatever lets you get results that will look like
A, (B, C, D)
But it would be really great if I returned a function multiple columns without any more than figuring.
Is there anything that can do something like this?
If the function func returns only 1 row with 3 values, such as : Create function function (input_val integer, out output_value 1 integer, out output_value 2 integer, out output_value 3 integer) AS $$ BEGIN output_val1: = input_val + 1; Output_val2: = input_val + 2; Output_val3: = input_val + 3; End; $$ LANGUAGE plpgsql;
and then you execute SELECT a, from func (a) to Table 1 you will get:
a | Integer integer Record ======== | ========== 1 | (2, 3, 4) 2 (3, 4, 5) 3. (4, 5, 6) But, if you execute:
SELECT a, (f) .output_val1, (f) .output_val2 (F) .out put_val 3 (choose one, fun (a) from Table 1 to F) AS X You will get:
a | Output_val1 | Output_val2 | Output_val3 integer | Integer | Integer | Integer ======== | ======================================= = 1 | 2 | 3 | 4 2 3 | 4 | 5 3 4 | 5 | 6 Or, if you execute (normal table expressions), use:
with temporarily (select one, function (A) Select from Table 1 F), (F). Output_value 1, (f) .output_value 2, (f) .output_value 3 to temporary You will also get:
one | Output_val1 | Output_val2 | Output_val3 integer | Integer | Integer | Integer ======== | ======================================= = 1 | 2 | 3 | 4 2 3 | 4 | 5 3 4 | 5 | 6 Note: You can also use the following questions to achieve similar results:
Select one, (f). * Select from (select one, with fax (A) table 1 to F) X or
with temporary (select one , Func (A) Table 1 F) Select A, (F). * Temp
Comments
Post a Comment