Select Column from Table to CSV
COPY videos(id, title)
to '/Users/computername/Desktop/example-with-column-names.csv'
delimiter ',' csv header;
Select Column from Table with WHERE to CSV
COPY
(
SELECT id, title
FROM videos
WHERE edition_id = 144
)
to '/Users/computername/Desktop/videos_with_tags.csv'
delimiter ',' csv header;
Select Columns and With Tags to CSV
I would like a CSV of all the videos that contain a tag.
The video_tags
table is a join table and can be looked this way.
COPY
(SELECT title, id
FROM videos v
WHERE EXISTS
(SELECT 1 FROM videos_tags p WHERE p.video_id = v.id)
)
to '/Users/computername/Desktop/videos_with_tags.csv'
delimiter ',' csv header;
With Select Columns Names with No Tags to CSV
I would like a CSV of all the videos that have no tags.
The video_tags
table is a join table and can be looked this way.
COPY
(SELECT id,title
FROM videos v
WHERE NOT EXISTS
(SELECT 1 FROM videos_tags p WHERE p.video_id = v.id)
)
to '/Users/computername/Desktop/videos_with_no_tags.csv'
delimiter ',' csv header;