Menu

[r8320]: / trunk / database / create_postgresql.sql  Maximize  Restore  History

Download this file

389 lines (346 with data), 13.9 kB

  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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*==============================================================*/
/* Database name: PostgreSql */
/* DBMS name: PostgreSQL 7 */
/* Created on: 04.02.2003 19:59:06 */
/*==============================================================*/
/*==============================================================*/
/* Table : blob_values */
/*==============================================================*/
create table blob_values (
b_id INT4 not null,
b_text TEXT null,
b_image OID null,
primary key (b_id)
);
/*==============================================================*/
/* Table : date_values */
/*==============================================================*/
create table date_values (
d_id INT4 not null,
d_date DATE null,
d_time TIME without time zone null,
d_datetime TIMESTAMP without time zone null,
d_timestamp TIMESTAMP without time zone null,
primary key (d_id)
);
/*==============================================================*/
/* Table : default_values */
/*==============================================================*/
create table default_values
(
d_id SERIAL not null,
d_fld1 INT4 default 123456,
d_fld2 FLOAT4 default 123.456,
d_fld3 VARCHAR(10) default 'xyz',
d_fld4 DATE default '2003-12-11',
d_fld5 TIME default '23:12:11',
d_fld6 TIMESTAMP default '2003-12-11 23:12:11',
primary key (d_id)
);
/*==============================================================*/
/* Table : default_values2 */
/*==============================================================*/
create table default_values2
(
d_id SERIAL not null,
d_fld1 FLOAT4 default 123.456,
d_fld2 INT4 default 123456,
d_fld3 DATE default '2003-12-11',
d_fld4 VARCHAR(10) default 'xyz',
d_fld5 TIMESTAMP default '2003-12-11 23:12:11',
d_fld6 TIME default '23:12:11',
primary key (d_id)
);
/*==============================================================*/
/* Table : department */
/*==============================================================*/
create table department (
dep_id SERIAL not null,
dep_name VARCHAR(20) null,
dep_shname CHAR(5) null,
dep_address VARCHAR(255) null,
primary key (dep_id)
);
/*==============================================================*/
/* Table : equipment */
/*==============================================================*/
create table equipment (
eq_id SERIAL not null,
eq_name VARCHAR(30) null,
eq_type INT2 null,
eq_cost NUMERIC(9,4) null,
eq_date DATE null,
woff_date DATE null,
primary key (eq_id)
);
/*==============================================================*/
/* Table : equipment2 */
/*==============================================================*/
create table equipment2 (
dep_id INT4 not null,
eq_id INT4 not null,
primary key (dep_id, eq_id),
foreign key (dep_id) references department (dep_id)
on delete restrict on update restrict,
foreign key (eq_id) references equipment (eq_id)
on delete restrict on update restrict
);
/*==============================================================*/
/* Table : number_values */
/*==============================================================*/
create table number_values (
n_id INT4 not null,
n_tint INT2 null,
n_sint INT2 null,
n_int INT4 null,
n_bdecimal INT8 null,
n_numeric NUMERIC(9,4) null,
n_float FLOAT8 null,
n_real FLOAT4 null,
n_dprecission FLOAT8 null,
n_money MONEY null,
primary key (n_id)
);
/*==============================================================*/
/* Table : people */
/*==============================================================*/
create table people (
p_id SERIAL not null,
p_dep_id INT2 null,
p_name VARCHAR(40) null,
p_begin_work TIME without time zone null,
p_end_work TIME without time zone null,
p_picture BYTEA null,
p_resume TEXT null,
p_redundant INT2 null,
primary key (p_id),
foreign key (p_dep_id) references department (dep_id)
on delete restrict on update restrict
);
/*==============================================================*/
/* Table : string_values */
/*==============================================================*/
create table string_values (
s_id INT4 not null,
s_char CHAR(255) null,
s_varchar VARCHAR(255) null,
s_nchar CHAR(255) null,
s_nvarchar VARCHAR(255) null,
s_bit CHAR(255) null,
s_varbit CHAR(1024) null,
primary key (s_id)
);
/*==============================================================*/
/* Table : not_null_values */
/*==============================================================*/
create table not_null_values
(
n_id int not null,
n_varchar VARCHAR(255) not null,
primary key (n_id)
);
/*==============================================================*/
/* Table : cargo */
/*==============================================================*/
create table cargo (
c_id SERIAL not null,
c_dep_id INT2 null,
c_name CHAR(10) null,
c_seal INT2 null,
c_date_came TIMESTAMP without time zone null,
c_date_out TIMESTAMP without time zone null,
c_weight FLOAT8 null,
c_width INT4 null,
c_height INT4 null,
c_cost FLOAT4 null,
c_attributes CHAR(10) null,
primary key (c_id),
foreign key (c_dep_id) references department (dep_id)
on delete restrict on update restrict
);
/*==============================================================*/
/* Table : Case_Sensitive */
/*==============================================================*/
create table "Case_Sensitive" (
cs_id INT4 not null,
"Cs_Data1" INT4,
"cs_data1" INT4,
"cs data1" INT4,
primary key (cs_id)
);
/*==============================================================*/
/* Table : Spaced Names */
/*==============================================================*/
create table "Spaced Names" (
cs_id INTEGER not null,
"Cs Data1" INTEGER,
"cs data2" INTEGER,
"cS data3" INTEGER,
primary key (cs_id)
);
/*==============================================================*/
/* Table : case_sensitive */
/*==============================================================*/
create table case_sensitive (
cs_id INT4 not null,
"CS_DATA1" INT4,
"CS_Data2" INT4,
"Cs_Data3" INT4,
primary key (cs_id)
);
/*==============================================================*/
/* Table : high_load */
/*==============================================================*/
create table high_load (
hl_id SERIAL,
stBoolean BOOLEAN,
stByte INT2,
stShort INT2,
stInteger INTEGER,
stLong INT8,
stFloat FLOAT4,
stDouble FLOAT8,
stBigDecimal NUMERIC(18,4),
stString VARCHAR(100),
stUnicodeString VARCHAR(255),
stBytes BYTEA,
stDate DATE,
stTime TIME without time zone,
stTimestamp TIMESTAMP without time zone,
stGUID CHAR(38),
stAsciiStream TEXT,
stUnicodeStream TEXT,
stBinaryStream BYTEA,
primary key (hl_id)
);
/*==============================================================*/
/* Table : bcd_values */
/*==============================================================*/
create table bcd_values
(
id INTEGER NOT NULL,
curr18_4 NUMERIC(18,4),
curr15_2 NUMERIC(15,2),
curr10_4 NUMERIC(10,4),
curr4_4 NUMERIC(4,4),
bigd18_1 NUMERIC(18,1),
bigd18_5 NUMERIC(18,5),
bigd12_10 NUMERIC(12,10),
bigd18_18 NUMERIC(18,18),
primary key (id)
);
DELIMITER //
/*==============================================================*/
/* Stored procedure: procedure1 */
/*==============================================================*/
CREATE FUNCTION procedure1(INT4) RETURNS integer
AS 'SELECT 1 AS RESULT;'
LANGUAGE SQL;
//
/*==============================================================*/
/* Stored procedure: procedure2 */
/*==============================================================*/
CREATE FUNCTION procedure2() RETURNS refcursor AS '
DECLARE
ref refcursor;
BEGIN
OPEN ref FOR SELECT eq_name FROM equipment;
RETURN ref;
END;
' LANGUAGE 'plpgsql';
//
/*==============================================================*/
/* Stored procedure: ABTEST */
/*==============================================================*/
CREATE FUNCTION "ABTEST" (
p1 integer,
p2 integer,
p3 varchar,
out p4 integer,
out p5 varchar
)
RETURNS record AS
$body$
BEGIN
p4 = p1 * 10 + p2;
p5 = p3 || p3;
END;
$body$
LANGUAGE 'plpgsql';
//
/*==============================================================*/
/* Stored procedure: proc_nonames */
/*==============================================================*/
CREATE FUNCTION proc_nonames (
integer,
integer,
out integer
)
RETURNS integer AS
'SELECT $1 + $2'
LANGUAGE 'sql';
//
/*==============================================================*/
/* Stored procedure: proc_onename */
/*==============================================================*/
CREATE FUNCTION proc_onename (
p1 integer,
integer,
out integer
)
RETURNS integer AS
'SELECT $1 + $2'
LANGUAGE 'sql';
//
/*==============================================================*/
/* Stored procedure: proc_noout */
/*==============================================================*/
CREATE FUNCTION proc_noout (
p1 integer,
integer
)
RETURNS integer AS
'SELECT $1 + $2'
LANGUAGE 'sql';
//
/*==============================================================*/
/* Stored procedure: proc_mixedorder */
/*==============================================================*/
CREATE FUNCTION proc_mixedorder (
OUT p1 integer,
INOUT p2 integer,
p3 integer
) AS
'SELECT $1 + $2, $1 * $2'
LANGUAGE 'sql';
//
/*==============================================================*/
/* Stored procedure: proc_composite */
/*==============================================================*/
CREATE TYPE compositetype AS (f1 integer, f2 integer);
//
CREATE FUNCTION proc_composite (
p1 integer,
p2 integer
)
RETURNS compositetype AS
'SELECT cast(($1, $2) as compositetype)'
LANGUAGE 'sql';
//
/*==============================================================*/
/* Stored procedure: proc_set */
/*==============================================================*/
CREATE FUNCTION proc_set ()
RETURNS SETOF VARCHAR AS
'SELECT eq_name FROM equipment'
LANGUAGE 'sql';
//
DELIMITER ;
/*==============================================================*/
/* Grant privileges to columns */
/*==============================================================*/
--grant update(p_resume, p_redundant) on people to postgres;
/*==============================================================*/
/* Grant privileges to table */
/*==============================================================*/
--grant select on people to postgres;
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.