I have a postgres database with a datetime field. I'd like to permanently convert it to a date field (i.e. remove the time element). What is the best way to go about that? Is there a way to do it in place without having to dump the table into a new table?
Assuming you mean a timestamp with "datetime".
ALTER TABLE foo ALTER COLUMN bar TYPE date;
Create new temporary field and UPDATE yourtable SET newfield = oldfield::date
with proper conversion function and then just remove old field and rename the new field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With