Answer the question
In order to leave comments, you need to log in
Creating a table in postgresql - TIME WITH TIME ZONE?
I'm just learning Java and SQL. I am trying to create a table in java code using Postgresql DBMS.
I'm trying to write code like this:
String requests = "CREATE TABLE REQUESTS" +
"(ID INT id_request NOT NULL," +
"time_request TIME WITH TIME ZONE NOT NULL";
statement.executeUpdate(requests);
Answer the question
In order to leave comments, you need to log in
You just need to use database syntax correctly. There are all sorts of brackets and commas sometimes ...
CREATE TABLE REQUESTS (
ID INT,
id_request INT NOT NULL,
time_request TIME WITH TIME ZONE NOT NULL
);
You missed the closing parenthesis in your query.
The type TIME WITH TIME ZONE
exists, but it's a bit weird because without a date (and this type is only about the time within a day - from 00:00 to 23:59), the zone is somewhat meaningless.
It is necessary to store the time (inside the day) - TIME.
Date without time - DATE.
Timestamp - TIMESTAMP (with time zone / without time zone).
https://www.postgresql.org/docs/current/datatype-d...
Difference between with time zone / without time zone: TIMESTAMP WITH TIME ZONE stored internally in UTC, converted from current time zone when written; TIMESTAMP WITHOUT TIME ZONE is stored as is, without conversions.
What to use depends on the application and the organization of work with the database in general. For one application (like a website), in principle, I don’t care
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question