Unix Technical Forum

Better error message for select_common_type()

This is a discussion on Better error message for select_common_type() within the pgsql Hackers forums, part of the PostgreSQL category; --> So I was informed today that UNION types integer and text cannot be matched. Alright, but it failed to ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-12-2008, 08:24 AM
Peter Eisentraut
 
Posts: n/a
Default Better error message for select_common_type()

So I was informed today that UNION types integer and text cannot be
matched. Alright, but it failed to tell which particular expressions
in this 3-branch, 30-columns-each UNION clause in a 100-line statement
it was talking about. So I made the attached patch to give some better
pointers. Example:

peter=# values(0,1), (1::bigint,2), ('text'::text,3);
ERROR: 42804: VALUES types bigint at position 2 and text at position 3
cannot be matched in instance 1

I'm not sure about the terminology "position" and "instance"; they're
just two coordinates to get at the problem.

None of this will help if you have multiple unrelated clauses that
invoke select_common_type(), but that might be better handled using the
parser location mechanism.

Comments?

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-12-2008, 08:24 AM
Gregory Stark
 
Posts: n/a
Default Re: Better error message for select_common_type()

"Peter Eisentraut" <peter_e@gmx.net> writes:

> peter=# values(0,1), (1::bigint,2), ('text'::text,3);
> ERROR: 42804: VALUES types bigint at position 2 and text at position 3
> cannot be matched in instance 1
>
> I'm not sure about the terminology "position" and "instance"; they're
> just two coordinates to get at the problem.


Wouldn't that just be column 1 in rows 2 and 3?

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-12-2008, 08:24 AM
Peter Eisentraut
 
Posts: n/a
Default Re: Better error message for select_common_type()

Gregory Stark wrote:
> "Peter Eisentraut" <peter_e@gmx.net> writes:
> > peter=# values(0,1), (1::bigint,2), ('text'::text,3);
> > ERROR: 42804: VALUES types bigint at position 2 and text at
> > position 3 cannot be matched in instance 1
> >
> > I'm not sure about the terminology "position" and "instance";
> > they're just two coordinates to get at the problem.

>
> Wouldn't that just be column 1 in rows 2 and 3?


In this case yes, but the routine is also used for UNION, IN, GREATEST,
JOIN/USING and others.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-12-2008, 08:24 AM
Peter Eisentraut
 
Posts: n/a
Default Re: Better error message for select_common_type()

Tom Lane wrote:
> +1 on using the parser location mechanism and avoiding the
> terminology problem altogether.


I figured we would let the parser only point to the UNION or VALUES or
whatever word. It would be fairly cumbersome to drag the individual
expression positions down into select_common_value() for full
precision.

> I fear though that we're not set up
> to have multiple locations in one error report. Will it be
> sufficient if we point at one of the two offending expressions? (I'd
> guess pointing at the second makes the most sense, if feasible.)


I don't think that would help. In the example I was looking at 90
expression and I had no idea in most cases what their results types
are, so if it tells me that the 15th expression somewhere doesn't
match, I would need to know which is the other mismatching one.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-12-2008, 08:24 AM
Tom Lane
 
Posts: n/a
Default Re: Better error message for select_common_type()

Peter Eisentraut <peter_e@gmx.net> writes:
> Tom Lane wrote:
>> +1 on using the parser location mechanism and avoiding the
>> terminology problem altogether.


> I figured we would let the parser only point to the UNION or VALUES or
> whatever word. It would be fairly cumbersome to drag the individual
> expression positions down into select_common_value() for full
> precision.


Possibly. I was thinking of demanding that callers pass an additional
list containing positions for the expressions, but hadn't looked to see
how easy that might be. In any case, if we need to point at both
expressions then it's not gonna work.

For the VALUES case, the suggestion of "row" and "column" terminology
seems the right thing, but for UNION it would be better to use "branch"
perhaps ("row" certainly seems misleading). How can we make that work
without indulging in untranslatable keyword-insertion?

Another possibility is "alternative" and "column", which seems like it
applies more or less equally poorly to both cases.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-12-2008, 08:24 AM
Alvaro Herrera
 
Posts: n/a
Default Re: Better error message for select_common_type()

Tom Lane wrote:

> For the VALUES case, the suggestion of "row" and "column" terminology
> seems the right thing, but for UNION it would be better to use "branch"
> perhaps ("row" certainly seems misleading). How can we make that work
> without indulging in untranslatable keyword-insertion?
>
> Another possibility is "alternative" and "column", which seems like it
> applies more or less equally poorly to both cases.


Maybe it would be good to have distinctive terminology if at all
possible, as it will be clearer for both cases.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-12-2008, 08:24 AM
Gregory Stark
 
Posts: n/a
Default Re: Better error message for select_common_type()


"Tom Lane" <tgl@sss.pgh.pa.us> writes:

> For the VALUES case, the suggestion of "row" and "column" terminology
> seems the right thing, but for UNION it would be better to use "branch"
> perhaps ("row" certainly seems misleading). How can we make that work
> without indulging in untranslatable keyword-insertion?


Hm, I guess the SQL spec terminology in both cases would be "table
expression".

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-15-2008, 10:47 PM
Tom Lane
 
Posts: n/a
Default Re: Better error message for select_common_type()

Peter Eisentraut <peter_e@gmx.net> writes:
> ... I'm not sure about the terminology "position" and "instance"; they're
> just two coordinates to get at the problem.


> None of this will help if you have multiple unrelated clauses that
> invoke select_common_type(), but that might be better handled using the
> parser location mechanism.


Were there any objections to changing this patch so that it reports
the second expression's parser location, instead of some arbitrary
numbers? The way I'm envisioning doing it is:

1. Invent an exprLocation() function (comparable to, say, exprType)
that knows how to get the parser location from any subtype of Node that
has one.

2. Make a variant of select_common_type() that takes a list of Exprs
instead of just type OIDs. It can get the type IDs from these
using exprType(), and it can get their locations using exprLocation()
if needed.

We could almost just replace the current form of select_common_type()
with the version envisioned in #2. In a quick grep, there is only
one usage of select_common_type() that isn't invoking it on a list
of exprType() results that could be trivially changed over to the
underlying expressions instead --- and that is in
transformSetOperationTree, which may be dealing with inputs that
are previously-resolved output types for child set operations.
I'm not sure about a better way to complain about type mismatches in
nested set operations, anyway. We could possibly keep track of one of
the sub-expressions that had determined the resolved output type, and
point to that, but it would likely seem a bit arbitrary to the user.
Thoughts anyone?

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-15-2008, 10:47 PM
Bruce Momjian
 
Posts: n/a
Default Re: Better error message for select_common_type()


Added to TODO:

* Improve reporting of UNION type mismatches

http://archives.postgresql.org/pgsql...4/msg00944.php
http://archives.postgresql.org/pgsql...3/msg00597.php


---------------------------------------------------------------------------

Peter Eisentraut wrote:
> So I was informed today that UNION types integer and text cannot be
> matched. Alright, but it failed to tell which particular expressions
> in this 3-branch, 30-columns-each UNION clause in a 100-line statement
> it was talking about. So I made the attached patch to give some better
> pointers. Example:
>
> peter=# values(0,1), (1::bigint,2), ('text'::text,3);
> ERROR: 42804: VALUES types bigint at position 2 and text at position 3
> cannot be matched in instance 1
>
> I'm not sure about the terminology "position" and "instance"; they're
> just two coordinates to get at the problem.
>
> None of this will help if you have multiple unrelated clauses that
> invoke select_common_type(), but that might be better handled using the
> parser location mechanism.
>
> Comments?
>
> --
> Peter Eisentraut
> http://developer.postgresql.org/~petere/


[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate


--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

-
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:29 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com