Imagine what I want here that I have a table with the line A . I have to: 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 : and then you execute But, if you execute: You will get: Or, if you execute (normal table expressions), use: You will also get: Note: You can also use the following questions to achieve similar results: or
SELECT A, from func (A) table,
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;
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)
SELECT a, (f) .output_val1, (f) .output_val2 (F) .out put_val 3 (choose one, fun (a) from Table 1 to F) AS X
a | Output_val1 | Output_val2 | Output_val3 integer | Integer | Integer | Integer ======== | ======================================= = 1 | 2 | 3 | 4 2 3 | 4 | 5 3 4 | 5 | 6
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
one | Output_val1 | Output_val2 | Output_val3 integer | Integer | Integer | Integer ======== | ======================================= = 1 | 2 | 3 | 4 2 3 | 4 | 5 3 4 | 5 | 6
Select one, (f). * Select from (select one, with fax (A) table 1 to F) X
with temporary (select one , Func (A) Table 1 F) Select A, (F). * Temp
Comments
Post a Comment