Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insertion syntax for interval data type in postgres

I created a table with following the fields and I have used a interval field to store duration of the courses. I want to insert interval time in DD:HH and couldn't find the syntax for it.

Anybody can help me with this insertion syntax with above format DD:HH . Thanks in advance.

CREATE TABLE practical.course
(
  course_id character(3) primary key,
  course_name character varying(30),
  duration interval,
  dept_id integer references practical.department(dept_id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE practical.course
  OWNER TO postgres;
like image 883
Mark Randy Avatar asked Aug 03 '16 17:08

Mark Randy


People also ask

How do I create an interval in PostgreSQL?

In PostgreSQL, the make_interval() function creates an interval from years, months, weeks, days, hours, minutes and seconds fields. You provide the years, months, weeks, days, hours, minutes and/or seconds fields, and it will return an interval in the interval data type.

What is interval data type in Postgres?

In PostgreSQL the interval data type is used to store and manipulate a time period. It holds 16 bytes of space and ranging from -178, 000, 000 years to 178, 000, 000 years. It also has additional attribute called “precision (denoted by p)” that can be used to set the level of precision in the query results.

How does interval work in PostgreSQL?

In PostgreSQL, the Interval is another type of data type used to store and deploy Time in years, months, days, hours, minutes, seconds, etc. And the months and days values are integers values, whereas the second's field can be the fractions values.

How do you insert data into a table in Pgadmin 4?

Expand your table properties by clicking on it in the pgAdmin4 legend. Right-click on 'Constraints', select 'Create' --> 'Primary Key'to define a primary key column.


1 Answers

You can insert as follows..

insert into practical.course(course_id,course_name, duration, dept_id)
values('104','Mathematical Engineering','40:00:00',1);

If you want to add days you can add 'no_of_days 40:00:00' instead '40:00:00'. You can insert in different formats and they are available in above link on the comment.

like image 140
Sidath Bhanuka Randeniya Avatar answered Oct 28 '22 14:10

Sidath Bhanuka Randeniya