|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.104 2001/10/2505:49:39 momjian Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.105 2001/11/12 20:05:24 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -806,6 +806,37 @@ exprTypmod(Node *expr)
|
806 | 806 | caseT_RelabelType:
|
807 | 807 | return ((RelabelType*)expr)->resulttypmod;
|
808 | 808 | break;
|
| 809 | +caseT_CaseExpr: |
| 810 | +{ |
| 811 | +/* |
| 812 | + * If all the alternatives agree on type/typmod, return |
| 813 | + * that typmod, else use -1 |
| 814 | + */ |
| 815 | +CaseExpr*cexpr= (CaseExpr*)expr; |
| 816 | +Oidcasetype=cexpr->casetype; |
| 817 | +int32typmod; |
| 818 | +List*arg; |
| 819 | + |
| 820 | +if (!cexpr->defresult) |
| 821 | +return-1; |
| 822 | +if (exprType(cexpr->defresult)!=casetype) |
| 823 | +return-1; |
| 824 | +typmod=exprTypmod(cexpr->defresult); |
| 825 | +if (typmod<0) |
| 826 | +return-1;/* no point in trying harder */ |
| 827 | +foreach(arg,cexpr->args) |
| 828 | +{ |
| 829 | +CaseWhen*w= (CaseWhen*)lfirst(arg); |
| 830 | + |
| 831 | +Assert(IsA(w,CaseWhen)); |
| 832 | +if (exprType(w->result)!=casetype) |
| 833 | +return-1; |
| 834 | +if (exprTypmod(w->result)!=typmod) |
| 835 | +return-1; |
| 836 | +} |
| 837 | +returntypmod; |
| 838 | +} |
| 839 | +break; |
809 | 840 | default:
|
810 | 841 | break;
|
811 | 842 | }
|
|