Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7b06d99

Browse files
author
Thomas G. Lockhart
committed
Backend code redefinitions to allow read/write
of integer Unix system times.
1 parent 8d30b40 commit 7b06d99

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

contrib/unixdate/unixdate.sql

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- unixdate
2+
-- Routines to convert int4 (Unix system time) to datetime
3+
-- and int4 (delta time) to timespan
4+
--
5+
-- Thomas Lockhart (lockhart@alumni.caltech.edu)
6+
-- 1997-11-25
7+
--
8+
-- This cheats and reuses existing code in the standard package.
9+
-- Can not include this directly because built-in functions are optimized
10+
-- into a cache and the duplicate function names abstime_datetime() and
11+
-- reltime_timespan() result in duplicate constants.
12+
--
13+
-- This works with Postgres v6.2 and higher.
14+
15+
--
16+
-- Conversions from integer to datetime
17+
--
18+
19+
CREATE FUNCTION abstime_datetime(int4)
20+
RETURNS datetime
21+
AS '-' LANGUAGE 'internal';
22+
23+
CREATE FUNCTION datetime(int4)
24+
RETURNS datetime
25+
AS 'select abstime_datetime($1)' LANGUAGE 'SQL';
26+
27+
CREATE FUNCTION reltime_timespan(int4)
28+
RETURNS timespan
29+
AS '-' LANGUAGE 'internal';
30+
31+
CREATE FUNCTION timespan(int4)
32+
RETURNS timespan
33+
AS 'select reltime_timespan($1)' LANGUAGE 'SQL';
34+
35+
--
36+
-- Conversions back to integer
37+
--
38+
39+
CREATE FUNCTION datetime_abstime(datetime)
40+
RETURNS int4
41+
AS '-' LANGUAGE 'internal';
42+
43+
CREATE FUNCTION utime(datetime)
44+
RETURNS int4
45+
AS 'select datetime_abstime($1)' LANGUAGE 'SQL';
46+
47+
CREATE FUNCTION timespan_reltime(timespan)
48+
RETURNS int4
49+
AS '-' LANGUAGE 'internal';
50+
51+
CREATE FUNCTION uspan(timespan)
52+
RETURNS int4
53+
AS 'select timespan_reltime($1)' LANGUAGE 'SQL';
54+

0 commit comments

Comments
 (0)