U
U
username52022-03-26 22:08:27
PostgreSQL
username5, 2022-03-26 22:08:27

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);

I understand that I indicate the type "TIME WITH TIME ZONE" most likely incorrectly. Tried googling how to specify the type, found nothing. Can you tell me how to write this type?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slava Rozhnev, 2022-03-27
@username5

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
);

https://sqlize.online/sql/psql14/b17e764b2527c0fc3...

G
galaxy, 2022-03-27
@galaxy

You missed the closing parenthesis in your query.
The type TIME WITH TIME ZONEexists, 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 question

Ask a Question

731 491 924 answers to any question