Johnny Bravo
Johnny Bravo

Reputation: 41

Switch psql output to HTML temporarily

I have to create a script that saves the output of my command to a HTML file. I got something like that:

\o file.html
\pset format html
SELECT * FROM clients;
\o

It works pretty well, but the problem is that it changes my format to HTML while I'm in classic mode. Is there any easy way to just export the output of the SELECT statement in HTML format without turning on HTML mode permanently?

Upvotes: 1

Views: 517

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247865

You can do that by replacing the semicolon with the appropriate \g directive:

SELECT * FROM clients \g (format=html) file.html

Upvotes: 3

Related Questions