Skip to content
Advertisement

Using update inside of PL/pgSQL

To begin with, I am a newbie to SQL and PostgreSQL. It might be a silly beginner’s mistake.

^This isn’t working provides me with an error

SQL Error [42601]: ERROR: syntax error at or near “update”
Where: PL/pgSQL function temporary_function_for_getting(text,bigint,json) line 13 at RETURN QUERY .

The update query works fine by itself not sure what i am doing wrong. Would appreciate if anyone could point me to the resource and/or a better way of doing the same process .

Advertisement

Answer

You seem to want an update CTE for the base query. Try something like this:

Note that the update will not update any rows if either $1 or $2 is NULL, because the where clause will evaluate to NULL — filtering out all rows.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement