1

The code bellow is giving error on w_add_ax_extra(1, 'k', 'v') previously it was w_add_ax_extra(some_id, kv.k, kv.v) I changed it to k, v to reproduce the same error

declare kv record; begin -- Lines skipped for kv in select * from (select (each(extras)).*) as f(k,v) loop raise notice 'key=%,value=%',kv.k,kv.v; w_add_ax_extra(1, 'k', 'v'); end loop; -- Lines Skipped end 

I am getting Syntax Error but could not understand what I am missing

ERROR: syntax error at or near "w_add_ax_extra" LINE 1: w_add_ax_extra(1, 'k', 'v') 

However If I do dummy = w_add_ax_extra(1, 'k', 'v') it works. Yes this function returns an integer. But I don't need to store it here. Is it mandatory to hold the return value ?

1 Answer 1

7

From the fine manual:

39.5.2. Executing a Command With No Result

[...]

Sometimes it is useful to evaluate an expression or SELECT query but discard the result, for example when calling a function that has side-effects but no useful result value. To do this in PL/pgSQL, use the PERFORM statement:

PERFORM query; 

Emphasis mine. You're not calling the function by saying something like f();, you need to perform f(); or select f() into ...;:

for kv in select * from (select (each(extras)).*) as f(k,v) loop raise notice 'key=%,value=%',kv.k,kv.v; perform w_add_ax_extra(1, 'k', 'v'); end loop; 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It Fixed. But things are not clear :( I copy pasted that f(k,v) however only f works too. so I removed the (k,v) part. Oh! sorry it doesn't work without (k,v)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.