1998-08-30 21:37:51 +02:00
|
|
|
-- datetime_functions.sql --
|
|
|
|
--
|
1997-11-05 22:38:25 +01:00
|
|
|
-- SQL code to define the new date and time functions and operators
|
1998-08-30 21:37:51 +02:00
|
|
|
--
|
|
|
|
-- Copyright (c) 1998, Massimo Dal Zotto <dz@cs.unitn.it>
|
|
|
|
--
|
|
|
|
-- This file is distributed under the GNU General Public License
|
|
|
|
-- either version 2, or (at your option) any later version.
|
1997-11-05 22:38:25 +01:00
|
|
|
|
1998-08-30 21:37:51 +02:00
|
|
|
-- Define the new time functions.
|
1997-11-05 22:38:25 +01:00
|
|
|
--
|
|
|
|
create function hhmm_in(opaque) returns time
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function hhmm_out(opaque) returns int4
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function hhmm(time) returns time
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function time_difference(time,time) returns time
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function time_hours(time) returns int4
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function time_minutes(time) returns int4
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function time_seconds(time) returns int4
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function as_minutes(time) returns int4
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function as_seconds(time) returns int4
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function date_day(date) returns int4
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function date_month(date) returns int4
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function date_year(date) returns int4
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function currenttime() returns time
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
|
|
|
create function currentdate() returns date
|
|
|
|
as 'MODULE_PATHNAME'
|
|
|
|
language 'c';
|
|
|
|
|
1998-08-30 21:37:51 +02:00
|
|
|
-- Define new operator - for time.
|
1997-11-05 22:38:25 +01:00
|
|
|
--
|
|
|
|
create operator - (
|
|
|
|
leftarg=time,
|
|
|
|
rightarg=time,
|
|
|
|
procedure=time_difference);
|
|
|
|
|
1998-08-30 21:37:51 +02:00
|
|
|
-- Define functions to switch from time to hhmm representation.
|
1997-11-05 22:38:25 +01:00
|
|
|
--
|
|
|
|
-- select hhmm_mode();
|
|
|
|
-- select time_mode();
|
|
|
|
--
|
|
|
|
create function hhmm_mode() returns text
|
|
|
|
as 'update pg_type set typinput =''hhmm_in'' where typname=''time'';
|
1999-06-05 21:09:48 +02:00
|
|
|
update pg_type set typoutput=''hhmm_out'' where typname=''time'';
|
|
|
|
select ''hhmm_mode''::text;'
|
1997-11-05 22:38:25 +01:00
|
|
|
language 'sql';
|
|
|
|
|
|
|
|
create function time_mode() returns text
|
|
|
|
as 'update pg_type set typinput =''time_in'' where typname=''time'';
|
1999-06-05 21:09:48 +02:00
|
|
|
update pg_type set typoutput=''time_out'' where typname=''time'';
|
|
|
|
select ''time_mode''::text;'
|
1997-11-05 22:38:25 +01:00
|
|
|
language 'sql';
|
|
|
|
|
|
|
|
-- Use these to do the updates manually
|
|
|
|
--
|
|
|
|
-- update pg_type set typinput ='hhmm_in' where typname='time';
|
|
|
|
-- update pg_type set typoutput='hhmm_out' where typname='time';
|
|
|
|
--
|
|
|
|
-- update pg_type set typinput ='time_in' where typname='time';
|
|
|
|
-- update pg_type set typoutput='time_out' where typname='time';
|
|
|
|
|
|
|
|
-- end of file
|