0

I want to create default timestamp column in an existing table.

My first query is

"ALTER TABLE {table_name} ADD COLUMN modifiedDate timestamp without time zone"

This works and successfully adds the column.

However the second query

ALTER TABLE {table_name} ALTER modifiedDate SET DEFAULT '2001-01-01 00:00:00'::timestamp without time zone;

fails to update all the rows on the column to contain that timestamp.

I was following this SO post.

I also tried in one query

"ALTER TABLE {table_name} ADD COLUMN modifiedDate timestamp without time zone" SET DEFAULT '2001-01-01 00:00:00'::timestamp without time zone;

but that gave an error syntax error at or near "00"

1 Answer 1

1

Silly mistake.

ALTER TABLE {table_name} ADD COLUMN modifiedDate timestamp without time zone NOT NULL DEFAULT '2001-01-01 00:00:00'::timestamp without time zone;

The SET should not be in the one liner.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.