jackc / pgtype

MIT License
308 stars 110 forks source link

Implementing time (without date) with time zone ? #76

Open pragyanaryal opened 3 years ago

pragyanaryal commented 3 years ago

Hello, I am having trouble implementing time with time zone without date postgres type. I could only see time or timestamp or timestampz implementation and think it is not what i need. Can anyone help me with this ? I have a time of day in a for a certain time zone, that I need to store in postgres. This is what I am trying to insert inside db, image

But, db throws an error stating date/field out of range. image

What correction should I make ?

jackc commented 3 years ago

You could use the pgtype.Time type for the PostgreSQL time type.

You can probably use it for time with time zone as well, but I wouldn't recommend it. The official PostgreSQL docs recommend against using that type at all (https://www.postgresql.org/docs/current/datatype-datetime.html).

The type time with time zone is defined by the SQL standard, but the definition exhibits properties which lead to questionable usefulness. In most cases, a combination of date, time, timestamp without time zone, and timestamp with time zone should provide a complete range of date/time functionality required by any application.

pragyanaryal commented 3 years ago

Thanks. Hello, I did a small hack to store time as I needed, I formatted the time in 5:45:00+541 format, which is a string. Pgx, successfully inserted the data, and my db readily approved the format. Now upon fetching the data it cannot parse the time, any more. Any idea or suggestion on it ?

jackc commented 3 years ago

What are you trying to scan it into? I would expect you could scan it into a string.