File: 1434

package info (click to toggle)
postgresql 6.3.2-15
  • links: PTS
  • area: main
  • in suites: slink
  • size: 21,136 kB
  • ctags: 15,441
  • sloc: ansic: 162,182; sh: 5,538; java: 5,143; yacc: 4,891; tcl: 4,778; sql: 4,120; makefile: 2,653; lex: 906; cpp: 839; python: 836; perl: 678; asm: 70; csh: 5; sed: 2
file content (352 lines) | stat: -rw-r--r-- 10,491 bytes parent folder | download | duplicates (2)
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
*** ./backend/parser/parse_clause.c.orig	Thu May 21 10:19:17 1998
--- ./backend/parser/parse_clause.c	Mon May 25 13:53:37 1998
***************
*** 192,208 ****
  	 *    it will not be projected into the final tuple.
  	 *          daveh@insightdist.com    5/20/98
  	 */  
! 	if ( ! target_result)  {  
  		List   *p_target = tlist;
- 		Ident *missingTargetId = (Ident *)makeNode(Ident);
  		TargetEntry *tent = makeNode(TargetEntry);
  		
- 		/*   Fill in the constructed Ident node   */
- 		missingTargetId->type = T_Ident;
- 		missingTargetId->name = palloc(strlen(sortgroupby->name) + 1);
- 		strcpy(missingTargetId->name, sortgroupby->name);
  
! 		transformTargetId(pstate, missingTargetId, tent, missingTargetId->name, TRUE);
  
  		/* Add to the end of the target list */
  		while (lnext(p_target) != NIL)  {
--- 192,223 ----
  	 *    it will not be projected into the final tuple.
  	 *          daveh@insightdist.com    5/20/98
  	 */  
! 	if ( ! target_result && sortgroupby->name)   {
  		List   *p_target = tlist;
  		TargetEntry *tent = makeNode(TargetEntry);
  		
  
! 		if (sortgroupby->range)  {
! 			Attr *missingTarget = (Attr *)makeNode(Attr);
! 			missingTarget->type = T_Attr;
! 
! 			missingTarget->relname = palloc(strlen(sortgroupby->range) + 1);
! 			strcpy(missingTarget->relname, sortgroupby->range);
! 
! 			missingTarget->attrs = lcons(makeString(sortgroupby->name), NIL);
! 
! 			transformTargetId(pstate, (Node*)missingTarget, tent, sortgroupby->name, TRUE);
! 		}
! 		else  {
! 			Ident *missingTarget = (Ident *)makeNode(Ident);
! 			missingTarget->type = T_Ident;
! 
! 			missingTarget->name = palloc(strlen(sortgroupby->name) + 1);
! 			strcpy(missingTarget->name, sortgroupby->name);
! 
! 			transformTargetId(pstate, (Node*)missingTarget, tent, sortgroupby->name, TRUE);
! 		}
! 
  
  		/* Add to the end of the target list */
  		while (lnext(p_target) != NIL)  {
*** ./backend/parser/parse_target.c.orig	Thu May 21 12:51:33 1998
--- ./backend/parser/parse_target.c	Thu May 21 13:21:09 1998
***************
*** 46,52 ****
   */
  void
  transformTargetId(ParseState *pstate,
! 				Ident *ident,
  				TargetEntry *tent,
  				char *resname,
  				int16 resjunk)
--- 46,52 ----
   */
  void
  transformTargetId(ParseState *pstate,
! 				Node *node,
  				TargetEntry *tent,
  				char *resname,
  				int16 resjunk)
***************
*** 60,66 ****
  	 * relation names (even though they can be stored in
  	 * Ident nodes, too)
  	 */
! 	expr = transformIdent(pstate, (Node *) ident, EXPR_COLUMN_FIRST);
  	type_id = exprType(expr);
  	if (nodeTag(expr) == T_Var)
  		type_mod = ((Var *) expr)->vartypmod;
--- 60,66 ----
  	 * relation names (even though they can be stored in
  	 * Ident nodes, too)
  	 */
! 	expr = transformExpr(pstate, node, EXPR_COLUMN_FIRST);
  	type_id = exprType(expr);
  	if (nodeTag(expr) == T_Var)
  		type_mod = ((Var *) expr)->vartypmod;
***************
*** 105,111 ****
  					identname = ((Ident *) res->val)->name;
  					handleTargetColname(pstate, &res->name, NULL, identname);
  					resname = (res->name) ? res->name : identname;
! 					transformTargetId(pstate, (Ident*)res->val, tent, resname, FALSE);
  					break;
  				}
  			case T_ParamNo:
--- 105,111 ----
  					identname = ((Ident *) res->val)->name;
  					handleTargetColname(pstate, &res->name, NULL, identname);
  					resname = (res->name) ? res->name : identname;
! 					transformTargetId(pstate, (Node*)res->val, tent, resname, FALSE);
  					break;
  				}
  			case T_ParamNo:
*** ./include/parser/parse_target.h.orig	Thu May 21 14:46:09 1998
--- ./include/parser/parse_target.h	Thu May 21 14:46:27 1998
***************
*** 24,30 ****
  
  extern List *transformTargetList(ParseState *pstate, List *targetlist);
  extern List *makeTargetNames(ParseState *pstate, List *cols);
! extern void transformTargetId(ParseState *pstate, Ident *ident,
  	TargetEntry *tent, char *resname, int16 resjunk);
  
  #endif							/* PARSE_TARGET_H */
--- 24,30 ----
  
  extern List *transformTargetList(ParseState *pstate, List *targetlist);
  extern List *makeTargetNames(ParseState *pstate, List *cols);
! extern void transformTargetId(ParseState *pstate, Node *node,
  	TargetEntry *tent, char *resname, int16 resjunk);
  
  #endif							/* PARSE_TARGET_H */
*** ./test/regress/sql/tests.orig	Mon May 25 13:36:24 1998
--- ./test/regress/sql/tests	Mon May 25 13:36:43 1998
***************
*** 60,62 ****
--- 60,63 ----
  select_views
  alter_table
  portals_p2
+ junkfilter

--------------39936BA36BB1A87A01EFF060
Content-Type: text/plain; charset=us-ascii; name="junkfilter.out"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="junkfilter.out"

QUERY: CREATE TABLE test_missing_target (a int, b int, c char(8));
QUERY: INSERT INTO test_missing_target VALUES (0, 1, 'XXXX');
QUERY: INSERT INTO test_missing_target VALUES (1, 2, 'AAAA');
QUERY: INSERT INTO test_missing_target VALUES (2, 2, 'AAAA');
QUERY: INSERT INTO test_missing_target VALUES (3, 3, 'BBBB');
QUERY: INSERT INTO test_missing_target VALUES (4, 3, 'BBBB');
QUERY: INSERT INTO test_missing_target VALUES (5, 3, 'BBBB');
QUERY: INSERT INTO test_missing_target VALUES (6, 4, 'CCCC');
QUERY: INSERT INTO test_missing_target VALUES (7, 4, 'CCCC');
QUERY: INSERT INTO test_missing_target VALUES (8, 4, 'CCCC');
QUERY: INSERT INTO test_missing_target VALUES (9, 4, 'CCCC');
QUERY: SELECT c, count(*) FROM test_missing_target GROUP BY test_missing_target.c;
c       |count
--------+-----
AAAA    |    2
BBBB    |    3
CCCC    |    4
XXXX    |    1
(4 rows)

QUERY: SELECT count(*) FROM test_missing_target GROUP BY test_missing_target.c;
count
-----
    2
    3
    4
    1
(4 rows)

QUERY: SELECT count(*) FROM test_missing_target GROUP BY a ORDER BY b;
ERROR:  parser: illegal use of aggregates or non-group column in target list
QUERY: SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b;
count
-----
    1
    2
    3
    4
(4 rows)

QUERY: SELECT test_missing_target.b, count(*) FROM test_missing_target GROUP BY b ORDER BY b;
b|count
-+-----
1|    1
2|    2
3|    3
4|    4
(4 rows)

QUERY: SELECT c FROM test_missing_target ORDER BY a;
c       
--------
XXXX    
AAAA    
AAAA    
BBBB    
BBBB    
BBBB    
CCCC    
CCCC    
CCCC    
CCCC    
(10 rows)

QUERY: SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b desc;
count
-----
    4
    3
    2
    1
(4 rows)

QUERY: SELECT count(*) FROM test_missing_target ORDER BY 1 desc;
count
-----
   10
(1 row)

QUERY: SELECT c, count(*) FROM test_missing_target GROUP BY 1;
c       |count
--------+-----
AAAA    |    2
BBBB    |    3
CCCC    |    4
XXXX    |    1
(4 rows)

QUERY: SELECT c, count(*) FROM test_missing_target GROUP BY 3;
ERROR:  left hand side of operator < has an unknown type, probably a bad attribute name
QUERY: SELECT count(*) FROM test_missing_target x, test_missing_target y
	WHERE x.a = y.a
	GROUP BY b ORDER BY b;
ERROR:  Column b is ambiguous
QUERY: SELECT x.b, count(*) FROM test_missing_target x, test_missing_target y
	WHERE x.a = y.a
	GROUP BY x.b;
b|count
-+-----
1|    1
2|    2
3|    3
4|    4
(4 rows)

QUERY: SELECT count(*) FROM test_missing_target x, test_missing_target y
	WHERE x.a = y.a
	GROUP BY x.b;
count
-----
    1
    2
    3
    4
(4 rows)

QUERY: SELECT count(*) INTO TABLE test_missing_target2
FROM test_missing_target x, test_missing_target y
	WHERE x.a = y.a
	GROUP BY x.b;
QUERY: SELECT * FROM test_missing_target2;
count
-----
    1
    2
    3
    4
(4 rows)

QUERY: drop table test_missing_target;
QUERY: drop table test_missing_target2;

--------------39936BA36BB1A87A01EFF060
Content-Type: text/plain; charset=us-ascii; name="junkfilter.sql"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="junkfilter.sql"

-- load test data
CREATE TABLE test_missing_target (a int, b int, c char(8));
INSERT INTO test_missing_target VALUES (0, 1, 'XXXX');
INSERT INTO test_missing_target VALUES (1, 2, 'AAAA');
INSERT INTO test_missing_target VALUES (2, 2, 'AAAA');
INSERT INTO test_missing_target VALUES (3, 3, 'BBBB');
INSERT INTO test_missing_target VALUES (4, 3, 'BBBB');
INSERT INTO test_missing_target VALUES (5, 3, 'BBBB');
INSERT INTO test_missing_target VALUES (6, 4, 'CCCC');
INSERT INTO test_missing_target VALUES (7, 4, 'CCCC');
INSERT INTO test_missing_target VALUES (8, 4, 'CCCC');
INSERT INTO test_missing_target VALUES (9, 4, 'CCCC');


--   w/ existing GROUP BY target
SELECT c, count(*) FROM test_missing_target GROUP BY test_missing_target.c;

--   w/o existing GROUP BY target using a relation name in GROUP BY clause
SELECT count(*) FROM test_missing_target GROUP BY test_missing_target.c;

--   w/o existing GROUP BY target and w/o existing a different ORDER BY target
--   failure expected
SELECT count(*) FROM test_missing_target GROUP BY a ORDER BY b;

--   w/o existing GROUP BY target and w/o existing same ORDER BY target
SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b;

--   w/ existing GROUP BY target using a relation name in target
SELECT test_missing_target.b, count(*) FROM test_missing_target GROUP BY b ORDER BY b;

--   w/o existing GROUP BY target
SELECT c FROM test_missing_target ORDER BY a;

--   w/o existing ORDER BY target
SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b desc;

--   group using reference number
SELECT count(*) FROM test_missing_target ORDER BY 1 desc;

--   order using reference number
SELECT c, count(*) FROM test_missing_target GROUP BY 1;

--   group using reference number out of range
--   failure expected
SELECT c, count(*) FROM test_missing_target GROUP BY 3;

--   group w/o existing GROUP BY and ORDER BY target under ambigious condition
--   failure expected
SELECT count(*) FROM test_missing_target x, test_missing_target y 
	WHERE x.a = y.a
	GROUP BY b ORDER BY b;

--   group w/ existing GROUP BY target under ambigious condition
SELECT x.b, count(*) FROM test_missing_target x, test_missing_target y 
	WHERE x.a = y.a
	GROUP BY x.b;

--   group w/o existing GROUP BY target under ambigious condition
SELECT count(*) FROM test_missing_target x, test_missing_target y 
	WHERE x.a = y.a
	GROUP BY x.b;

--   group w/o existing GROUP BY target under ambigious condition
--   into a table
SELECT count(*) INTO TABLE test_missing_target2 
FROM test_missing_target x, test_missing_target y 
	WHERE x.a = y.a
	GROUP BY x.b;
SELECT * FROM test_missing_target2;

--   Cleanup
drop table test_missing_target;
drop table test_missing_target2;