Functions with variable number of input parameters

后端 未结 2 950
故里飘歌
故里飘歌 2020-12-01 20:18

I\'m creating a stored procedure (function) in a PostgreSQL DB, which updates a table depending on its input. In order to create a variable number of parameter function, I\'

2条回答
  •  爱一瞬间的悲伤
    2020-12-01 20:36

    There are a few things you'll want to look into:

    • Dynamically building the SQL using the format function and its %I and %L specifiers, then executing it with EXECUTE ... USING; and

    • Using VARIADIC parameters to take variable numbers of arguments to the function, with the caveat that they must all be the same data type.

提交回复
热议问题