Обсуждение: What does this error message mean?

Поиск
Список
Период
Сортировка

What does this error message mean?

От
Ken Tanzer
Дата:
Hi.  I got an error message reported to me that I've never seen before, and I'm not quite sure what it means or what would cause it.  When I re-run the query now, it runs without complaint, so the problem seems to have gone away.  Which of course I don't understand either!  Would be nice to know for the future.  This is on 9.2.5.

The message says the error is at line 195 of a function.  I've attached the function source in case it's relevant/helpful.

(And BTW, how exactly is that line number counted? Does the "CREATE FUNCTION" statement count as line 1? Or does it start with the opening quote?  And it looks like whitespace and comments are preserved internally, so is it safe to assume the line number should match with a source file used to create the function?  My best guess is that line 195 in this case is "pay_test.is_deleted=false;" but that doesn't help me understand this error any better!

CREATE FUNCTION blah blah $$
DECLARE... Line 1?

CREATE FUNCTION blah blah
$$

DECLARE... Line 1? 2?

CREATE FUNCTION blah blah
$$DECLARE... Line 1?


Here's the query:

INSERT INTO tbl_payment SELECT * FROM generate_payments ('12/1/2013','ASSIST_PRI','3852',sys_user()) WHERE NOT ROW(client_id,payment_type_code,payment_date) IN (SELECT client_id,payment_type_code,payment_date FROM payment_valid);

The error message was:

ERROR:  type of parameter 70 (text) does not match that when preparing the plan (unknown) CONTEXT: PL/pgSQL function generate_payments(date,text,integer,integer) line 195 at assignment

Thanks in advance for shedding any light on this.

Ken


--
AGENCY Software  
A data system that puts you in control
100% Free Software
(253) 245-3801

learn more about AGENCY or
follow the discussion.
Вложения

Re: What does this error message mean?

От
Tom Lane
Дата:
Ken Tanzer <ken.tanzer@gmail.com> writes:
> Hi.  I got an error message reported to me that I've never seen before, and
> I'm not quite sure what it means or what would cause it.

> ERROR:  type of parameter 70 (text) does not match that when preparing the
> plan (unknown) CONTEXT: PL/pgSQL function
> generate_payments(date,text,integer,integer) line 195 at assignment

I think this must mean that you changed the schema of table tbl_payment
during this session, and then re-ran the function.  plpgsql isn't as good
as it could be about dealing with intra-session changes of composite
types.  The reference to "parameter 70" seems a bit odd though, it doesn't
seem like you have anywhere near 70 variables in that function ...

> (And BTW, how exactly is that line number counted? Does the "CREATE
> FUNCTION" statement count as line 1?

In recent versions, the opening quote of the function's body string counts
as line 1.  If your attachment came through without extra wrapping, I'm
counting this as line 195:

        pay_test.comment=payment.comment;

(thinks about it for a bit)  Actually it seems more likely that a change
in the rowtype of "payment" caused this, ie some change in the output
column set of that "final_query" query.  Difficult to guess more than
that without more context.

            regards, tom lane


Re: What does this error message mean?

От
Ken Tanzer
Дата:

On Sun, Nov 17, 2013 at 6:20 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Ken Tanzer <ken.tanzer@gmail.com> writes:
> Hi.  I got an error message reported to me that I've never seen before, and
> I'm not quite sure what it means or what would cause it.

> ERROR:  type of parameter 70 (text) does not match that when preparing the
> plan (unknown) CONTEXT: PL/pgSQL function
> generate_payments(date,text,integer,integer) line 195 at assignment

I think this must mean that you changed the schema of table tbl_payment
during this session, and then re-ran the function.  plpgsql isn't as good
as it could be about dealing with intra-session changes of composite
types.  The reference to "parameter 70" seems a bit odd though, it doesn't
seem like you have anywhere near 70 variables in that function ...


(thinks about it for a bit)  Actually it seems more likely that a change
in the rowtype of "payment" caused this, ie some change in the output
column set of that "final_query" query.  Difficult to guess more than
that without more context.

                        regards, tom lane

Thanks Tom.  If you really mean it that the schema must have changed during the session, that seems impossible (er, highly unlikely).  The error was generated through a web app that doesn't know how to do any schema changing.

If there's a broader window, though, schema changes do seem plausible.  The type of that comment field hasn't changed, but on Friday I did some dropping and recreating of both the generate_payments function and the views it draws upon.  If the function was created before the view existed, would that account for this error?  (Leaving aside parameter 70, of course).  It is possible that this row was the first one generated by the function since the schema drops/creates on Friday.  (It actually looks like it was 9 minutes after another row, but that's based on comparing server time to a screenshot of a client's desktop with their clock showing, so I wouldn't put too much faith in that.)

And if this error was from the Friday schema changes, would it have auto-corrected itself so it only happened the one time?

Cheers,
Ken

--
AGENCY Software  
A data system that puts you in control
100% Free Software
(253) 245-3801

learn more about AGENCY or
follow the discussion.

Re: What does this error message mean?

От
Tom Lane
Дата:
Ken Tanzer <ken.tanzer@gmail.com> writes:
> And if this error was from the Friday schema changes, would it have
> auto-corrected itself so it only happened the one time?

Starting a fresh session would've "auto-corrected" it ...

            regards, tom lane


Re: What does this error message mean?

От
Ken Tanzer
Дата:
The type of that comment field hasn't changed

Oh, and I'm going to slight eat my words, or at least elaborate.  That comment field has been in all the views unchanged.  Until Tuesday, though, the field wasn't being used or referenced in the function.  So that line 195 is actually new as of Tuesday.  But the function was replaced at the time, and definitely has generated rows since then.

But thinking about it some more, the function runs one of 5 possible queries.  4 of them select NULL as comment (no cast), while the fifth (and the one that caused this error) selects 'a string'. That actually got me thinking more, and I can now reproduce the error.  If I run the query  with any of the NULL comments, and then with the string, the query consistently fails.  And actually if I run the string query first, the other 4 then will fail for the rest of the session.  (Example below.)  

I assume this will go away if I change my lazy query and cast my NULLs, but still wonder if this is something that should be expected to fail?

Thanks,
Ken

--'ASSIST'=untyped NULL comment, 'ASSIST_PRI'=string comment
SELECT * FROM generate_payments ('12/1/2013','ASSIST','3852',sys_user());
(one row returned)
SELECT * FROM generate_payments ('12/1/2013','ASSIST_PRI','3852',sys_user());
ERROR:  type of parameter 70 (text) does not match that when preparing the plan (unknown)
CONTEXT:  PL/pgSQL function generate_payments(date,text,integer,integer) line 195 at assignment

(quit psql, start psql)

SELECT * FROM generate_payments ('12/1/2013','ASSIST_PRI','3852',sys_user());
(one row returned)
SELECT * FROM generate_payments ('12/1/2013','ASSIST','3852',sys_user());
ERROR:  type of parameter 70 (unknown) does not match that when preparing the plan (text)
CONTEXT:  PL/pgSQL function generate_payments(date,text,integer,integer) line 195 at assignment


On Sun, Nov 17, 2013 at 7:03 PM, Ken Tanzer <ken.tanzer@gmail.com> wrote:

On Sun, Nov 17, 2013 at 6:20 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Ken Tanzer <ken.tanzer@gmail.com> writes:
> Hi.  I got an error message reported to me that I've never seen before, and
> I'm not quite sure what it means or what would cause it.

> ERROR:  type of parameter 70 (text) does not match that when preparing the
> plan (unknown) CONTEXT: PL/pgSQL function
> generate_payments(date,text,integer,integer) line 195 at assignment

I think this must mean that you changed the schema of table tbl_payment
during this session, and then re-ran the function.  plpgsql isn't as good
as it could be about dealing with intra-session changes of composite
types.  The reference to "parameter 70" seems a bit odd though, it doesn't
seem like you have anywhere near 70 variables in that function ...


(thinks about it for a bit)  Actually it seems more likely that a change
in the rowtype of "payment" caused this, ie some change in the output
column set of that "final_query" query.  Difficult to guess more than
that without more context.

                        regards, tom lane

Thanks Tom.  If you really mean it that the schema must have changed during the session, that seems impossible (er, highly unlikely).  The error was generated through a web app that doesn't know how to do any schema changing.

If there's a broader window, though, schema changes do seem plausible.  The type of that comment field hasn't changed, but on Friday I did some dropping and recreating of both the generate_payments function and the views it draws upon.  If the function was created before the view existed, would that account for this error?  (Leaving aside parameter 70, of course).  It is possible that this row was the first one generated by the function since the schema drops/creates on Friday.  (It actually looks like it was 9 minutes after another row, but that's based on comparing server time to a screenshot of a client's desktop with their clock showing, so I wouldn't put too much faith in that.)

And if this error was from the Friday schema changes, would it have auto-corrected itself so it only happened the one time?

Cheers,
Ken

--
AGENCY Software  
A data system that puts you in control
100% Free Software

learn more about AGENCY or
follow the discussion.



--
AGENCY Software  
A data system that puts you in control
100% Free Software
(253) 245-3801

learn more about AGENCY or
follow the discussion.

Re: What does this error message mean?

От
Tom Lane
Дата:
Ken Tanzer <ken.tanzer@gmail.com> writes:
> But thinking about it some more, the function runs one of 5 possible
> queries.  4 of them select NULL as comment (no cast), while the fifth (and
> the one that caused this error) selects 'a string'.

Ah.  Fixing that so all the variants produce the same (explicit) type
should take care of this.

> I assume this will go away if I change my lazy query and cast my NULLs, but
> still wonder if this is something that should be expected to fail?

Ideally it wouldn't, but it's not clear what it'd cost to fix it.
If we just silently replanned when the query output types changed,
then this type of situation would work but would carry a large hidden
performance penalty.  That's not too appetizing either.

            regards, tom lane


Re: What does this error message mean?

От
Ken Tanzer
Дата:
Agreed.  Although given that you can cast text to unknown, and NULL to text, it's not intuitively clear why this would have to fail absent replanning.  However, knowing nothing about Postgres internals, I'm happy to take your word for it! Thanks again.

Ken


On Sun, Nov 17, 2013 at 7:59 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Ken Tanzer <ken.tanzer@gmail.com> writes:
> But thinking about it some more, the function runs one of 5 possible
> queries.  4 of them select NULL as comment (no cast), while the fifth (and
> the one that caused this error) selects 'a string'.

Ah.  Fixing that so all the variants produce the same (explicit) type
should take care of this.

> I assume this will go away if I change my lazy query and cast my NULLs, but
> still wonder if this is something that should be expected to fail?

Ideally it wouldn't, but it's not clear what it'd cost to fix it.
If we just silently replanned when the query output types changed,
then this type of situation would work but would carry a large hidden
performance penalty.  That's not too appetizing either.

                        regards, tom lane



--
AGENCY Software  
A data system that puts you in control
100% Free Software
(253) 245-3801

learn more about AGENCY or
follow the discussion.