Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
blob: f4e593d329ac8a6b2c791221b42d2d6c890fb05b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
-- PostgreSQL catalog extensions for ODBC compliance
-- $Header: /cvsroot/pgsql/src/interfaces/odbc/Attic/odbc.sql,v 1.1 2000/09/18 20:11:37 petere Exp $


-- In the current driver, ODBC functions must map directly into a
-- Postgres function. So in some cases we must create a compatible
-- function.


-- truncate on the left
CREATE FUNCTION ltrunc(text, integer)
    RETURNS text
    AS 'SELECT substring($1 FROM 1 FOR $2)'
    LANGUAGE 'SQL';

-- truncate on the right
CREATE FUNCTION rtrunc(text, integer)
    RETURNS text
    AS 'SELECT substring($1 FROM (char_length($1)-($2)+1) FOR $2)'
    LANGUAGE 'SQL';

CREATE FUNCTION space(integer)
    RETURNS text
    AS 'SELECT lpad('''', $1, '' '')'
    LANGUAGE 'SQL';

--
-- Mathematical functions
--

CREATE FUNCTION truncate(numeric,integer)
    RETURNS numeric
    AS 'SELECT trunc($1, $2)'
    LANGUAGE 'SQL';

--
-- Date/time functions for v7.0
--

CREATE FUNCTION curdate()
    RETURNS date
    AS 'SELECT CAST(''now'' AS date)'
    LANGUAGE 'SQL';

CREATE FUNCTION curtime()
    RETURNS time
    AS 'SELECT CAST(''now'' AS time)'
    LANGUAGE 'SQL';

CREATE FUNCTION dayname(timestamp)
    RETURNS text
    AS 'SELECT to_char($1,''Day'')'
    LANGUAGE 'SQL';

CREATE FUNCTION dayofmonth(timestamp)
    RETURNS integer
    AS 'SELECT  CAST(date_part(''day'', $1) AS integer)'
    LANGUAGE 'SQL';

CREATE FUNCTION dayofweek(timestamp)
    RETURNS integer
    AS 'SELECT ( CAST(date_part(''dow'', $1) AS integer) + 1)'
    LANGUAGE 'SQL';

CREATE FUNCTION dayofyear(timestamp)
    RETURNS integer
    AS 'SELECT  CAST(date_part(''doy'', $1) AS integer)'
    LANGUAGE 'SQL';

CREATE FUNCTION hour(timestamp)
    RETURNS integer
    AS 'SELECT CAST(date_part(''hour'', $1) AS integer)'
    LANGUAGE 'SQL';

CREATE FUNCTION minute(timestamp)
    RETURNS integer
    AS 'SELECT CAST(date_part(''minute'', $1) AS integer)'
    LANGUAGE 'SQL';

CREATE FUNCTION odbc_month(timestamp)
    RETURNS integer
    AS 'SELECT CAST(date_part(''month'', $1) AS integer)'
    LANGUAGE 'SQL';

CREATE FUNCTION monthname(timestamp)
    RETURNS text
    AS 'SELECT to_char($1, ''Month'')'
    LANGUAGE 'SQL';

CREATE FUNCTION quarter(timestamp)
    RETURNS integer
    AS 'SELECT CAST(date_part(''quarter'', $1) AS integer)'
    LANGUAGE 'SQL';

CREATE FUNCTION second(timestamp)
    RETURNS integer
    AS 'SELECT CAST(date_part(''second'', $1) AS integer)'
    LANGUAGE 'SQL';

/*
-- The first argument is an integer constant denoting the units
-- of the second argument. Until we know the actual values, we
-- cannot implement these. - thomas 2000-04-11
CREATE FUNCTION timestampadd(integer,integer,timestamp)
    RETURNS timestamp
    AS 'SELECT CAST(($3 + ($2 * $1)) AS timestamp)'
    LANGUAGE 'SQL';

CREATE FUNCTION timestampdiff(integer,integer,timestamp)
    RETURNS timestamp
    AS 'SELECT CAST(($3 + ($2 * $1)) AS timestamp)'
    LANGUAGE 'SQL';
*/

CREATE FUNCTION week(timestamp)
    RETURNS integer
    AS 'SELECT CAST(date_part(''week'', $1) AS integer)'
    LANGUAGE 'SQL';

CREATE FUNCTION year(timestamp)
    RETURNS integer
    AS 'SELECT CAST(date_part(''year'', $1) AS integer)'
    LANGUAGE 'SQL';

--
-- System functions.
--

/*
CREATE FUNCTION database()
    RETURNS text
    AS 'SELECT ...'
    LANGUAGE 'SQL';
*/

CREATE FUNCTION odbc_user()
    RETURNS text
    AS 'SELECT CAST(USER AS text)'
    LANGUAGE 'SQL';