PostgreSQL: How to pass table/view name as a parameter to function in PostgreSQL?

后端 未结 1 710
我寻月下人不归
我寻月下人不归 2021-01-26 00:53

For example: I have a VIEW called \"view1\" which contains \'name\' and \'slno\' columns, now i want it to be display using FUNCTION called \"f1\" as shown below:

--Func

相关标签:
1条回答
  • 2021-01-26 01:33

    This is dynamic SQL, so you need EXECUTE.

    RETURN QUERY EXECUTE format('SELECT * FROM %I', "name");
    

    Separately, that's a weird thing to want to do.

    0 讨论(0)
提交回复
热议问题