Skip to content

Commit e47e9c4

Browse files
authored
Save_PostgreSQL_Result_to_File.sql
1 parent a4ec5af commit e47e9c4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Using \o Command
2+
3+
\o sql_result.txt --Specifying file path
4+
SELECT * from Student; --Storing Student record to the file
5+
\o --Resetting the output back to the terminal
6+
7+
8+
9+
-- Using Command Line Redirection
10+
-- exporting all rows from the Course table in the university database
11+
psql -d university -c "SELECT * from Course;" > /var/lib/postgresql/course_data.txt
12+
13+
14+
15+
16+
-- Using COPY TO SQL
17+
--exporting the content of the Department to the res.csv file
18+
COPY Department TO '/var/lib/postgresql/res.csv' DELIMITER ',' CSV HEADER;
19+
20+
21+
22+
23+

0 commit comments

Comments
 (0)