Expressions without type

Lists: pgsql-hackers
From: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Expressions without type
Date: 2012-08-22 12:48:52
Message-ID: CAFjFpRe5bOt9wbxD7HhW29+re8=APXxgHOOtKjj__4vczWR1mw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi All,
I need to check type of expressions appearing in a Query tree and I am
using exprType() for that. But for certain expressions their type is not
defined like List, FromExpr, JoinExpr. Such expressions are acceptable in
the code, but expressions which have a type need to obey certain criteria
like they can not be composite type etc. exprType() throws error when it's
passed expressions which do not have type and hence I can not use it
directly. Is there a function, which would tell me whether a given
expression can have a type or not?

--
Best Wishes,
Ashutosh Bapat
EntepriseDB Corporation
The Enterprise Postgres Company


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Expressions without type
Date: 2012-08-22 14:01:16
Message-ID: 14257.1345644076@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> writes:
> I need to check type of expressions appearing in a Query tree and I am
> using exprType() for that. But for certain expressions their type is not
> defined like List, FromExpr, JoinExpr. Such expressions are acceptable in
> the code, but expressions which have a type need to obey certain criteria
> like they can not be composite type etc. exprType() throws error when it's
> passed expressions which do not have type and hence I can not use it
> directly. Is there a function, which would tell me whether a given
> expression can have a type or not?

It seems to me that this is the result of fuzzy thinking. Neither
FromExpr nor JoinExpr can possibly occur in random places in a query
tree: they only appear in the join tree, all of which can be thought of
as returning SETOF RECORD if you want, but it doesn't seem very helpful
to apply exprType to the jointree. Lists likewise don't occur in any
context where it seems helpful to associate a type with the node tree.
So I think you need to think a bit harder about what you need to
accomplish and which parts of a query you need to accomplish it on.

regards, tom lane