PostgreSQL Commands

tags: #public #sql

1) Show the table structure in PostgreSQL

```sql
\d table_name
```

2) Display all tables sql \dt 3) Export as CSV sql \copy (SELECT expression) TO filename csv header; header - Include the header 4) Join topics with posts and export sql \ copy ( SELECT app_post.title, app_post.summary, array_to_string(array_agg(app_topic.slug), ',') FROM app_post_topics LEFT OUTER JOIN app_post ON app_post_topics.post_id = app_post.id LEFT OUTER JOIN app_topic ON app_post_topics.topic_id = app_topic.id GROUP BY app_post.id ) to posts.csv csv header;

Backlinks