2

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?

asked Oct 6, 2021 at 4:12

1 Answer 1

3

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
3
  • even if fun() returned something like SELECT * from...? Commented Oct 6, 2021 at 6:15
  • @Blender: Yes. Follow the link to read details in the manual. Commented Oct 6, 2021 at 14:14
  • Yeah it does not work in datagrip console sadly for me... Commented Oct 6, 2021 at 15:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.