sql - Return setof record with 1 row -
I am changing a PLPGSQL
function and I have a small problem. Post announcements:
Create or replace function permissions (_prinsl text) SETOF records $ BODY $ DECLARE ID integer: = 0; Rolero record;
In this case, in some cases, if
is handled by statements, and all of them, return UNION
is 1 For more queries, such as:
for roller (select SELECT 'role1' as role from WHERE id = table1.id) union (form of selection from table 2 Select 'role2') WHERE id = table2.id) UNION (selection as role3 'Table 3 WHERE id = role from table3.id)) LOOP RETURN Next Rolero; End loop; Return;
And it all works well, but in one case, I need to return a single query result, it will be a SETOF record
, but only with 1 before, so I did it so:
the (selection Rolero for 'role table as 4' 4 WHERE id = table4.id) LOOP RETURN NEXT Rolero; End loop; Return;
I also tried
Returns the choice of QUERY as 'role4' table 4 WHERE id = table4.id;
But in both cases I get an error similar to the response:
Error: the structure of the query does not match the result type of the function Description: Returned The type given does not match the expected type of text in unknown column 1. Do anyone have any idea how can I fix this?
You need a clear cast for the string ' Unlike the type 4 (
SELECT 'role4' By: AS role ... Usually, looping is more expensive for your simple examples as if you have already tested it.
Comments
Post a Comment