On Postgres, I want to load a select query into a csv file. But in the CSV file I want to put some values, that doesn't appear in the query, how do I do that? It's like:

select id, name, email  

And then have a Date, which I want to set default in every line. So the csv will be like:


closed as off-topic by MDCCL, LowlyDBA, mustaccio, hot2use, Md Haidar Ali Khan Oct 10 '18 at 3:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – MDCCL, LowlyDBA, mustaccio, Md Haidar Ali Khan
If this question can be reworded to fit the rules in the help center, please edit the question.


Just select the additional value:

select id, name, email, current_date as "date"
from the_table;


select id, name, email, date '2018-10-09' as "date"
from the_table;

You can COPY or \copy from an arbitrary query if you put parentheses around it.

\copy (select id, name, email, now() as "date" from example) to file.csv with (format csv)

Not the answer you're looking for? Browse other questions tagged or ask your own question.