sb9
sb9

Reputation: 316

How to set default time for a TIME column in table MySQL 5.7?

I want to set the default value in a TIME column in a MySQL DB table to be '08:00:00' regardless of timezone. I can't quite figure out the syntax.

create table venues (venue_id SERIAL PRIMARY KEY, name VARCHAR(100), address VARCHAR(250), open_time TIME DEFAULT '08:00:00'::TIME, close_time TIME DEFAULT '20:00:00'::TIME, activities VARCHAR(250);

It has a problem with how i'm trying to set the default values for the two TIME columns. I also tried using '08:00:00'::time without time zone

Upvotes: 0

Views: 226

Answers (2)

Schwern
Schwern

Reputation: 164679

'08:00:00'::TIME is how you do a type cast in Postgres, not MySQL. MySQL uses the SQL standard cast. Similarly time without time zone is a Postgres type.

You don't need a type cast at all, MySQL (and Postgres) will cast it to the column type.

create table venues (
    venue_id SERIAL PRIMARY KEY,
    name VARCHAR(100),
    address VARCHAR(250),
    open_time TIME DEFAULT '08:00:00',
    close_time TIME DEFAULT '20:00:00',
    activities VARCHAR(250)
);

dbfiddle

Upvotes: 1

sb9
sb9

Reputation: 316

::TIME casts are not needed for the TIME columns

Upvotes: 0

Related Questions