Sample Exam Questions
When starting psql, specify the --mode=csv option, and execute the following from the psql prompt:
SELECT ... > output.csv
When starting psql, specify >output.csv option to redirect the output, and then execute the following commands in the specified order:
\format csv
SELECT ...
After starting psql, execute the following commands in the specified order:
\o output.csv
\pset format csv
SELECT ....
Execute the following from the command line:
psql -c "SELECT ..." --csv > output.csv
Execute the following from the command line:
psql -c "SELECT ..." --format=csv > output.csv
※This sample exam is different from those that appear in the actual OSS-DB Exam.
2024/05/07
psql allows you to connect to a database, execute SQL, and output the results in various formats, but by default, the output is formatted as shown below.
select * from test;
id | val
----+-----
1 | aaa
You must specify options to create output files in CSV format.
You can export a CSV by combining two options: not aligning and specifying the delimiter character. However, there is an easier way to do this by specifying 'format csv' to the \pset meta-command. Also, since psql allows you to specify a file to output the results to with the \o meta-command, option C will output the results of the SELECT statement in CSV format to output.csv.
The command-line options for starting psql can do the same thing, and the --csv option is the same as the meta-command \pset format csv. You can also specify the SELECT statement to be executed with the -c option and the destination file name with redirection, as in option D.
So the correct answers are C and D.
© EDUCO All Rights Reserved.