~ubuntu-branches/ubuntu/lucid/psqlodbc/lucid

« back to all changes in this revision

Viewing changes to odbc.sql

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-05-13 10:47:36 UTC
  • Revision ID: james.westby@ubuntu.com-20040513104736-a530gmn0p3knep89
Tags: upstream-07.03.0200
ImportĀ upstreamĀ versionĀ 07.03.0200

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- PostgreSQL catalog extensions for ODBC compatibility
 
2
-- $Header: /usr/local/cvsroot/psqlodbc/psqlodbc/odbc.sql,v 1.7 2001/12/21 06:01:36 thomas Exp $
 
3
 
 
4
-- ODBC functions are described here:
 
5
-- <http://msdn.microsoft.com/library/en-us/odbc/htm/odbcscalar_functions.asp>
 
6
 
 
7
-- Note:  If we format this file consistently we can automatically
 
8
-- generate a corresponding "drop script".  Start "CREATE" in the first
 
9
-- column, and keep everything up to and including the argument list on
 
10
-- the same line.  See also the makefile rule.
 
11
 
 
12
 
 
13
-- String Functions
 
14
-- ++++++++++++++++
 
15
--
 
16
-- Built-in: ASCII, BIT_LENGTH, CHAR_LENGTH, CHARACTER_LENGTH, LTRIM,
 
17
--           OCTET_LENGTH, POSITION, REPEAT, RTRIM, SUBSTRING
 
18
-- Missing: DIFFERENCE, REPLACE, SOUNDEX, LENGTH (ODBC sense)
 
19
-- Keyword problems: CHAR
 
20
 
 
21
 
 
22
-- CHAR(code)
 
23
CREATE OR REPLACE FUNCTION "char"(integer) RETURNS text AS '
 
24
    SELECT chr($1);
 
25
' LANGUAGE SQL;
 
26
 
 
27
 
 
28
-- CONCAT(string1, string2)
 
29
CREATE OR REPLACE FUNCTION concat(text, text) RETURNS text AS '
 
30
    SELECT $1 || $2;
 
31
' LANGUAGE SQL;
 
32
 
 
33
 
 
34
-- INSERT(string1, start, len, string2)
 
35
CREATE OR REPLACE FUNCTION insert(text, integer, integer, text) RETURNS text AS '
 
36
    SELECT substring($1 from 1 for $2 - 1) || $4 || substring($1 from $2 + $3);
 
37
' LANGUAGE SQL;
 
38
 
 
39
 
 
40
-- LCASE(string)
 
41
CREATE OR REPLACE FUNCTION lcase(text) RETURNS text AS '
 
42
    SELECT lower($1);
 
43
' LANGUAGE SQL;
 
44
 
 
45
 
 
46
-- LEFT(string, count)
 
47
CREATE OR REPLACE FUNCTION left(text, integer) RETURNS text AS '
 
48
    SELECT substring($1 for $2);
 
49
' LANGUAGE SQL;
 
50
 
 
51
 
 
52
-- LOCATE(substring, string[, start])
 
53
CREATE OR REPLACE FUNCTION locate(text, text) RETURNS integer AS '
 
54
    SELECT position($1 in $2);
 
55
' LANGUAGE SQL;
 
56
CREATE OR REPLACE FUNCTION locate(text, text, integer) RETURNS integer AS '
 
57
    SELECT position($1 in substring($2 from $3)) + $3 - 1;
 
58
' LANGUAGE SQL;
 
59
 
 
60
 
 
61
-- RIGHT(string, count)
 
62
CREATE OR REPLACE FUNCTION right(text, integer) RETURNS text AS '
 
63
    SELECT substring($1 from char_length($1) - $2 + 1);
 
64
' LANGUAGE SQL;
 
65
 
 
66
 
 
67
-- SPACE(count)
 
68
CREATE OR REPLACE FUNCTION space(integer) RETURNS text AS '
 
69
    SELECT repeat('' '', $1);
 
70
' LANGUAGE SQL;
 
71
 
 
72
 
 
73
-- UCASE(string)
 
74
CREATE OR REPLACE FUNCTION ucase(text) RETURNS text AS '
 
75
    SELECT upper($1);
 
76
' LANGUAGE SQL;
 
77
 
 
78
 
 
79
-- Numeric Functions
 
80
-- +++++++++++++++++
 
81
--
 
82
-- Built-in: ABS, ACOS, ASIN, ATAN, ATAN2, COS, COT, DEGRESS, EXP,
 
83
--           FLOOR, MOD, PI, RADIANS, ROUND, SIGN, SIN, SQRT, TAN
 
84
-- Missing: LOG (ODBC sense)
 
85
 
 
86
 
 
87
-- CEILING(num)
 
88
CREATE OR REPLACE FUNCTION ceiling(numeric) RETURNS numeric AS '
 
89
    SELECT ceil($1);
 
90
' LANGUAGE SQL;
 
91
 
 
92
 
 
93
-- LOG10(num)
 
94
CREATE OR REPLACE FUNCTION log10(double precision) RETURNS double precision AS '
 
95
    SELECT log($1);
 
96
' LANGUAGE SQL;
 
97
CREATE OR REPLACE FUNCTION log10(numeric) RETURNS numeric AS '
 
98
    SELECT log($1);
 
99
' LANGUAGE SQL;
 
100
 
 
101
 
 
102
-- POWER(num, num)
 
103
CREATE OR REPLACE FUNCTION power(double precision, double precision)
 
104
  RETURNS double precision AS '
 
105
    SELECT pow($1, $2);
 
106
' LANGUAGE SQL;
 
107
CREATE OR REPLACE FUNCTION power(numeric, numeric)
 
108
  RETURNS numeric AS '
 
109
    SELECT pow($1, $2);
 
110
' LANGUAGE SQL;
 
111
 
 
112
 
 
113
-- RAND([seed])
 
114
CREATE OR REPLACE FUNCTION rand() RETURNS double precision AS '
 
115
    SELECT random();
 
116
' LANGUAGE SQL;
 
117
CREATE OR REPLACE FUNCTION rand(double precision) RETURNS double precision AS '
 
118
    SELECT setseed($1);
 
119
    SELECT random();
 
120
' LANGUAGE SQL;
 
121
 
 
122
 
 
123
-- TRUNCATE(num, places)
 
124
CREATE OR REPLACE FUNCTION truncate(numeric, integer) RETURNS numeric AS '
 
125
    SELECT trunc($1, $2);
 
126
' LANGUAGE SQL;
 
127
 
 
128
 
 
129
-- Time, Date, and Interval Functions
 
130
-- ++++++++++++++++++++++++++++++++++
 
131
--
 
132
-- Built-in: CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, EXTRACT, NOW
 
133
-- Missing: none
 
134
 
 
135
 
 
136
CREATE OR REPLACE FUNCTION curdate() RETURNS date AS '
 
137
    SELECT current_date;
 
138
' LANGUAGE SQL;
 
139
 
 
140
CREATE OR REPLACE FUNCTION curtime() RETURNS time with time zone AS '
 
141
    SELECT current_time;
 
142
' LANGUAGE SQL;
 
143
 
 
144
CREATE OR REPLACE FUNCTION odbc_timestamp() RETURNS timestamp with time zone AS '
 
145
    SELECT current_timestamp;
 
146
' LANGUAGE SQL;
 
147
 
 
148
CREATE OR REPLACE FUNCTION dayname(timestamp) RETURNS text AS '
 
149
    SELECT to_char($1,''Day'');
 
150
' LANGUAGE SQL;
 
151
 
 
152
CREATE OR REPLACE FUNCTION dayofmonth(timestamp) RETURNS integer AS '
 
153
    SELECT CAST(EXTRACT(day FROM $1) AS integer);
 
154
' LANGUAGE SQL;
 
155
 
 
156
CREATE OR REPLACE FUNCTION dayofweek(timestamp) RETURNS integer AS '
 
157
    SELECT CAST(EXTRACT(dow FROM $1) AS integer) + 1;
 
158
' LANGUAGE SQL;
 
159
 
 
160
CREATE OR REPLACE FUNCTION dayofyear(timestamp) RETURNS integer AS '
 
161
    SELECT CAST(EXTRACT(doy FROM $1) AS integer);
 
162
' LANGUAGE SQL;
 
163
 
 
164
CREATE OR REPLACE FUNCTION hour(timestamp) RETURNS integer AS '
 
165
    SELECT CAST(EXTRACT(hour FROM $1) AS integer);
 
166
' LANGUAGE SQL;
 
167
 
 
168
CREATE OR REPLACE FUNCTION minute(timestamp) RETURNS integer AS '
 
169
    SELECT CAST(EXTRACT(minute FROM $1) AS integer);
 
170
' LANGUAGE SQL;
 
171
 
 
172
CREATE OR REPLACE FUNCTION month(timestamp) RETURNS integer AS '
 
173
    SELECT CAST(EXTRACT(month FROM $1) AS integer);
 
174
' LANGUAGE SQL;
 
175
 
 
176
CREATE OR REPLACE FUNCTION monthname(timestamp) RETURNS text AS '
 
177
    SELECT to_char($1, ''Month'');
 
178
' LANGUAGE SQL;
 
179
 
 
180
CREATE OR REPLACE FUNCTION quarter(timestamp) RETURNS integer AS '
 
181
    SELECT CAST(EXTRACT(quarter FROM $1) AS integer);
 
182
' LANGUAGE SQL;
 
183
 
 
184
CREATE OR REPLACE FUNCTION second(timestamp) RETURNS integer AS '
 
185
    SELECT CAST(EXTRACT(second FROM $1) AS integer);
 
186
' LANGUAGE SQL;
 
187
 
 
188
/*
 
189
-- The first argument is an integer constant denoting the units
 
190
-- of the second argument. Until we know the actual values, we
 
191
-- cannot implement these. - thomas 2000-04-11
 
192
xCREATE OR REPLACE FUNCTION timestampadd(integer, integer, timestamp)
 
193
  RETURNS timestamp AS '
 
194
    SELECT CAST(($3 + ($2 * $1)) AS timestamp);
 
195
' LANGUAGE SQL;
 
196
 
 
197
xCREATE OR REPLACE FUNCTION timestampdiff(integer, integer, timestamp)
 
198
  RETURNS timestamp AS '
 
199
    SELECT CAST(($3 + ($2 * $1)) AS timestamp);
 
200
' LANGUAGE SQL;
 
201
*/
 
202
 
 
203
CREATE OR REPLACE FUNCTION week(timestamp) RETURNS integer AS '
 
204
    SELECT CAST(EXTRACT(week FROM $1) AS integer);
 
205
' LANGUAGE SQL;
 
206
 
 
207
CREATE OR REPLACE FUNCTION year(timestamp) RETURNS integer AS '
 
208
    SELECT CAST(EXTRACT(year FROM $1) AS integer);
 
209
' LANGUAGE SQL;
 
210
 
 
211
 
 
212
-- System Functions
 
213
-- ++++++++++++++++
 
214
--
 
215
-- Built-in: USER
 
216
-- Missing: DATABASE, IFNULL
 
217
 
 
218
CREATE OR REPLACE FUNCTION odbc_user() RETURNS text AS '
 
219
    SELECT CAST(current_user AS TEXT);
 
220
' LANGUAGE SQL;
 
221
 
 
222
CREATE OR REPLACE FUNCTION odbc_current_user() RETURNS text AS '
 
223
    SELECT CAST(current_user AS TEXT);
 
224
' LANGUAGE SQL;
 
225
 
 
226
CREATE OR REPLACE FUNCTION odbc_session_user() RETURNS text AS '
 
227
    SELECT CAST(session_user AS TEXT);
 
228
' LANGUAGE SQL;