aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas G. Lockhart <lockhart@fourpalms.org>1998-08-02 13:34:26 +0000
committerThomas G. Lockhart <lockhart@fourpalms.org>1998-08-02 13:34:26 +0000
commit7665e7b0a8ada42b0efa307e5feb9ba7bc0831a0 (patch)
treefdff5ad764cd1333b36f8d26afd1ae6c7a2debac
parent39844ac2c332af0b8df86e44ad7e56deafbbfd56 (diff)
downloadpostgresql-7665e7b0a8ada42b0efa307e5feb9ba7bc0831a0.tar.gz
postgresql-7665e7b0a8ada42b0efa307e5feb9ba7bc0831a0.zip
Allows the following query to succeed: "SELECT NULL ORDER BY 1;"
There are three or four cases in transformSortClause() and I had fixed only one case for UNION. A second case is now fixed, in the same way; I assigned INT4OID to the column type for the "won't actually happen" sort. Didn't want to skip the code entirely, since the backend needs to _try_ a sort to get the NULLs right. I'm not certain under what circumstances the other cases are invoked and these are not yet fixed up, though perhaps they don't need to be...
-rw-r--r--src/backend/parser/parse_clause.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
index a701ffca279..0e122999cbf 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.21 1998/07/14 03:51:42 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.22 1998/08/02 13:34:26 thomas Exp $
*
*-------------------------------------------------------------------------
*/
@@ -317,6 +317,10 @@ transformSortClause(ParseState *pstate,
{
List *s = NIL;
+#ifdef PARSEDEBUG
+printf("transformSortClause: entering\n");
+#endif
+
while (orderlist != NIL)
{
SortGroupBy *sortby = lfirst(orderlist);
@@ -326,7 +330,17 @@ transformSortClause(ParseState *pstate,
restarget = find_targetlist_entry(pstate, sortby, targetlist);
+#ifdef PARSEDEBUG
+printf("transformSortClause: find sorting operator for type %d\n",
+ restarget->resdom->restype);
+#endif
+
sortcl->resdom = resdom = restarget->resdom;
+
+ /* if we have InvalidOid, then this is a NULL field and don't need to sort */
+ if (resdom->restype == InvalidOid)
+ resdom->restype = INT4OID;
+
sortcl->opoid = oprid(oper(sortby->useOp,
resdom->restype,
resdom->restype, false));
@@ -389,6 +403,14 @@ transformSortClause(ParseState *pstate,
/* not a member of the sortclauses yet */
SortClause *sortcl = makeNode(SortClause);
+#ifdef PARSEDEBUG
+printf("transformSortClause: (2) find sorting operator for type %d\n",
+ tlelt->resdom->restype);
+#endif
+
+ if (tlelt->resdom->restype == InvalidOid)
+ tlelt->resdom->restype = INT4OID;
+
sortcl->resdom = tlelt->resdom;
sortcl->opoid = any_ordering_op(tlelt->resdom->restype);
@@ -423,6 +445,11 @@ transformSortClause(ParseState *pstate,
/* not a member of the sortclauses yet */
SortClause *sortcl = makeNode(SortClause);
+#ifdef PARSEDEBUG
+printf("transformSortClause: try sorting type %d\n",
+ tlelt->resdom->restype);
+#endif
+
sortcl->resdom = tlelt->resdom;
sortcl->opoid = any_ordering_op(tlelt->resdom->restype);
@@ -485,6 +512,13 @@ printf("transformUnionClause: types are %d -> %d\n", itype, otype);
{
((TargetEntry *)lfirst(prev_target))->resdom->restype = itype;
}
+#if FALSE
+ else
+ {
+ ((TargetEntry *)lfirst(prev_target))->resdom->restype = UNKNOWNOID;
+ ((TargetEntry *)lfirst(next_target))->resdom->restype = UNKNOWNOID;
+ }
+#endif
}
else if (itype == InvalidOid)
{