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;
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With