My function fun()
returned a long crosstab table generation string (varchar) that I can view with select fun()
. How to execute it not inside a function but from a console?
1 Answer 1
Use \gexec
in psql to execute what the query returns:
SELECT fun()\gexec
The manual:
Sends the current query buffer to the server, then treats each column of each row of the query's output (if any) as an SQL statement to be executed.
Read the manual for more details.
Related:
answered Oct 6, 2021 at 4:17
-
even if fun() returned something like
SELECT * from...
?Blender– Blender2021年10月06日 06:15:01 +00:00Commented Oct 6, 2021 at 6:15 -
@Blender: Yes. Follow the link to read details in the manual.Erwin Brandstetter– Erwin Brandstetter2021年10月06日 14:14:54 +00:00Commented Oct 6, 2021 at 14:14
-
Yeah it does not work in datagrip console sadly for me...Blender– Blender2021年10月06日 15:52:25 +00:00Commented Oct 6, 2021 at 15:52
lang-sql