postgresql/contrib/datetime/datetime_functions.sql.in
Marc G. Fournier eec4c7366f From: Massimo Dal Zotto <dz@cs.unitn.it>
Here is a tar file the new directories, which substitute the old ones
in contrib. Please remove the old directories array, datetime, miscutil,
string and userlock before unpacking the tar file in contrib.

Note that as the modules are now installed in lib/modules I install all
my sql code in lib/sql. In my opinion also the other contributors should
follow these rules.
1998-08-30 19:37:51 +00:00

100 lines
2.5 KiB
MySQL

-- datetime_functions.sql --
--
-- SQL code to define the new date and time functions and operators
--
-- 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.
-- Define the new time functions.
--
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';
-- Define new operator - for time.
--
create operator - (
leftarg=time,
rightarg=time,
procedure=time_difference);
-- Define functions to switch from time to hhmm representation.
--
-- select hhmm_mode();
-- select time_mode();
--
create function hhmm_mode() returns text
as 'update pg_type set typinput =''hhmm_in'' where typname=''time'';
update pg_type set typoutput=''hhmm_out'' where typname=''time''
select ''hhmm_mode''::text'
language 'sql';
create function time_mode() returns text
as 'update pg_type set typinput =''time_in'' where typname=''time'';
update pg_type set typoutput=''time_out'' where typname=''time''
select ''time_mode''::text'
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