Thread: ERROR: index row size

ERROR: index row size

From
"Rodrigo Sakai"
Date:
<div class="Section1"><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">  Hello,</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:10.0pt;
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">  Ok, I give up! Tried a lot of things in my code! But still get error on index row size. So, I’m
partof my code, if someone could help me! A valid value for this type is: ‘(03-jan-2007 , 15-may-2010)’</span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span style="font-size:10.0pt; 
font-family:Arial"> </span></font><p class="MsoNormal" style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">typedef struct t_periodo</span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier
New"">{</span></font><pclass="MsoNormal" style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">      DateADT           tvi;</span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier
New"">     DateADT           tvf;</span></font><p class="MsoNormal" style="margin-left:.5in"><font face="Courier New"
size="2"><spanstyle="font-size:10.0pt;font-family:"Courier New"">}     Periodo;</span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier
New""> </span></font><pclass="MsoNormal" style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">Datum</span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier
New"">periodo_in(PG_FUNCTION_ARGS)</span></font><pclass="MsoNormal" style="margin-left:.5in"><font face="Courier New"
size="2"><spanstyle="font-size:10.0pt;font-family:"Courier New"">{</span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">   
char   *str = PG_GETARG_CSTRING(0);</span></font><p class="MsoNormal" style="margin-left:.5in"><font face="Courier New"
size="2"><spanstyle="font-size:10.0pt;font-family:"Courier New"">    char    tvi_char[MAXDATEFIELDS];</span></font><p
class="MsoNormal"style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">    char    tvf_char[MAXDATEFIELDS];</span></font><p
class="MsoNormal"style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">    </span></font><p class="MsoNormal" style="margin-left:.5in"><font
face="CourierNew" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">    tvi_char = (char *)
palloc(strlen(MAXDATEFIELDS));</span></font><pclass="MsoNormal" style="margin-left:.5in"><font face="Courier New"
size="2"><spanstyle="font-size:10.0pt;font-family:"Courier New"">    tvf_char = (char *)
palloc(strlen(MAXDATEFIELDS));</span></font><pclass="MsoNormal" style="margin-left:.5in"><font face="Courier New"
size="2"><spanstyle="font-size:10.0pt;font-family:"Courier New"">    </span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">   
Periodo    *result;</span></font><p class="MsoNormal" style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">    </span></font><p class="MsoNormal" style="margin-left:.5in"><font
face="CourierNew" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">    if (sscanf(str, " ( %s , %s )",
tvi_char,tvf_char) != 2)</span></font><p class="MsoNormal" style="margin-left:.5in"><font face="Courier New"
size="2"><spanstyle="font-size:10.0pt;font-family:"Courier New"">        ereport(ERROR,</span></font><p
class="MsoNormal"style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">           
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),</span></font><pclass="MsoNormal" style="margin-left:.5in"><font
face="CourierNew" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">            errmsg("invalid input
syntaxfor periodo: \"%s\"", str)));</span></font><p class="MsoNormal" style="margin-left:.5in"><font face="Courier New"
size="2"><spanstyle="font-size:10.0pt;font-family:"Courier New"">            </span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">   
result->tvi= StringToDateADT(tvi_char);            </span></font><p class="MsoNormal" style="margin-left:.5in"><font
face="CourierNew" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">    result->tvi =
StringToDateADT(tvf_char);</span></font><pclass="MsoNormal" style="margin-left:.5in"><font face="Courier New"
size="2"><spanstyle="font-size:10.0pt;font-family:"Courier New"">    </span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">   
result= (Periodo *) palloc(sizeof(Periodo));</span></font><p class="MsoNormal" style="margin-left:.5in"><font
face="CourierNew" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">      </span></font><p
class="MsoNormal"style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">    if (result->tvi > result->tvf)</span></font><p
class="MsoNormal"style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">        ereport(ERROR,</span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier
New"">               (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),</span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier
New"">               errmsg("Initial date (TVi) must be smaller than final date (TVf)")));      </span></font><p
class="MsoNormal"style="margin-left:.5in"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">    </span></font><p class="MsoNormal" style="margin-left:.5in"><font
face="CourierNew" size="2"><span style="font-size:10.0pt;font-family:"Courier New"">   
PG_RETURN_POINTER(result);</span></font><pclass="MsoNormal" style="margin-left:.5in"><font face="Courier New"
size="2"><spanstyle="font-size:10.0pt;font-family:"Courier New"">}</span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier
New""> </span></font><pclass="MsoNormal"><font face="Courier New" size="2"><span style="font-size:10.0pt; 
font-family:"Courier New""> </span></font><p class="MsoNormal"><font face="Courier New" size="2"><span
style="font-size:10.0pt;
font-family:"Courier New"">  Please help me!</span></font><p class="MsoNormal"><font face="Courier New" size="2"><span
style="font-size:10.0pt;
font-family:"Courier New"">  Thanks in advance!</span></font><p class="MsoNormal" style="margin-left:.5in"><font
face="CourierNew" size="2"><span style="font-size:10.0pt;font-family:"Courier New""> </span></font><p class="MsoNormal"
style="margin-left:.5in"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier
New""> </span></font></div>

Re: ERROR: index row size

From
Jeremy Drake
Date:
Just glancing at this, a couple things stand out to me:

On Mon, 4 Jun 2007, Rodrigo Sakai wrote:

> Datum
> periodo_in(PG_FUNCTION_ARGS)
> {
>     char    *str = PG_GETARG_CSTRING(0);
>     char    tvi_char[MAXDATEFIELDS];
>     char    tvf_char[MAXDATEFIELDS];
>
>     tvi_char = (char *) palloc(strlen(MAXDATEFIELDS));

What are you doing here?  This is completely broken.  I think you meant to
say:

char *tvi_char;

tvi_char = palloc(MAXDATEFIELDS);

Or:

char tvi_char[MAXDATEFIELDS];

and no palloc.

>     tvf_char = (char *) palloc(strlen(MAXDATEFIELDS));

Same as above.

>
>     Periodo     *result;
>
>     if (sscanf(str, " ( %s , %s )", tvi_char, tvf_char) != 2)

This is asking for trouble if arbitrary input can be fed to this.

>         ereport(ERROR,
>             (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
>             errmsg("invalid input syntax for periodo: \"%s\"", str)));
>
>     result->tvi = StringToDateADT(tvi_char);
>     result->tvi = StringToDateADT(tvf_char);
>
>     result = (Periodo *) palloc(sizeof(Periodo));
>
>     if (result->tvi > result->tvf)
>         ereport(ERROR,
>                 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
>                 errmsg("Initial date (TVi) must be smaller than final date
> (TVf)")));
>
>     PG_RETURN_POINTER(result);
> }
>
>   Please help me!
>
>   Thanks in advance!

Hope this helps.

-- 
My love, he's mad, and my love, he's fleet,And a wild young wood-thing bore him!
The ways are fair to his roaming feet,And the skies are sunlit for him.
As sharply sweet to my heart he seemsAs the fragrance of acacia.
My own dear love, he is all my dreams --And I wish he were in Asia.    -- Dorothy Parker


Re: ERROR: index row size

From
Tom Lane
Date:
Jeremy Drake <pgsql@jdrake.com> writes:
>> char    tvi_char[MAXDATEFIELDS];
>> 
>> tvi_char = (char *) palloc(strlen(MAXDATEFIELDS));

> What are you doing here?  This is completely broken.

Indeed ... *please* tell us your compiler issued a warning about that.
If not an error --- none of the compilers I use will take it at all.
Maybe you need to get a real C compiler.

>> result->tvi = StringToDateADT(tvi_char);
>> result->tvi = StringToDateADT(tvf_char);
>> 
>> result = (Periodo *) palloc(sizeof(Periodo));

Well, you oughta allocate result before you store into it, not after,
and I bet you meant to assign to the tvi and tvf fields, not tvi twice.

Bad as these mistakes are, they don't directly explain why a later index
entry creation would fail.  What I'm betting is that your CREATE TYPE
command does not correctly describe the datatype size.  Based on this
code it should be pass-by-reference, fixed-size-8-bytes, but I'll bet
a nickel your CREATE TYPE says something else --- probably varlena.
        regards, tom lane


Re: ERROR: index row size

From
"Rodrigo Sakai"
Date:
  Hello Jeremy,
 You are right about:   char tvi_char[MAXDATEFIELDS];
 I have already tried this and didn't work too, it keeps giving the index
error!

 About:   if (sscanf(str, " ( %s , %s )", tvi_char, tvf_char) != 2)
 I test tvi_char and tvf_char with StringToDateADT(tvi_char). Just date
types are allowed!
 Any other suggestions?? Thanks!

-----Original Message-----
From: Jeremy Drake [mailto:pgsql@jdrake.com] 
Sent: segunda-feira, 4 de junho de 2007 00:23
To: Rodrigo Sakai
Cc: PostgreSQL Hackers
Subject: Re: [HACKERS] ERROR: index row size

Just glancing at this, a couple things stand out to me:

On Mon, 4 Jun 2007, Rodrigo Sakai wrote:

> Datum
> periodo_in(PG_FUNCTION_ARGS)
> {
>     char    *str = PG_GETARG_CSTRING(0);
>     char    tvi_char[MAXDATEFIELDS];
>     char    tvf_char[MAXDATEFIELDS];
>
>     tvi_char = (char *) palloc(strlen(MAXDATEFIELDS));

What are you doing here?  This is completely broken.  I think you meant to
say:

char *tvi_char;

tvi_char = palloc(MAXDATEFIELDS);

Or:

char tvi_char[MAXDATEFIELDS];

and no palloc.

>     tvf_char = (char *) palloc(strlen(MAXDATEFIELDS));

Same as above.

>
>     Periodo     *result;
>
>     if (sscanf(str, " ( %s , %s )", tvi_char, tvf_char) != 2)

This is asking for trouble if arbitrary input can be fed to this.

>         ereport(ERROR,
>             (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
>             errmsg("invalid input syntax for periodo: \"%s\"", str)));
>
>     result->tvi = StringToDateADT(tvi_char);
>     result->tvi = StringToDateADT(tvf_char);
>
>     result = (Periodo *) palloc(sizeof(Periodo));
>
>     if (result->tvi > result->tvf)
>         ereport(ERROR,
>                 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
>                 errmsg("Initial date (TVi) must be smaller than final date
> (TVf)")));
>
>     PG_RETURN_POINTER(result);
> }
>
>   Please help me!
>
>   Thanks in advance!

Hope this helps.

-- 
My love, he's mad, and my love, he's fleet,And a wild young wood-thing bore him!
The ways are fair to his roaming feet,And the skies are sunlit for him.
As sharply sweet to my heart he seemsAs the fragrance of acacia.
My own dear love, he is all my dreams --And I wish he were in Asia.    -- Dorothy Parker



Re: ERROR: index row size

From
"Rodrigo Sakai"
Date:
>Indeed ... *please* tell us your compiler issued a warning about that.

I did shell scripts that suppress the warnings, so it was a big mistake, I
agree! But I think my problem is not here!

> Well, you oughta allocate result before you store into it, not after,
> and I bet you meant to assign to the tvi and tvf fields, not tvi twice.
You are right again. But this happened because I copy and paste the example
with a different order. But in my code all this is ok!

>Bad as these mistakes are, they don't directly explain why a later index
>entry creation would fail.  What I'm betting is that your CREATE TYPE
>command does not correctly describe the datatype size.  Based on this
>code it should be pass-by-reference, fixed-size-8-bytes, but I'll bet
>a nickel your CREATE TYPE says something else --- probably varlena.

Humm, this can help! I will investigate! Thanks a lot!



Re: ERROR: index row size

From
"Rodrigo Sakai"
Date:
>but I'll bet
>a nickel your CREATE TYPE says something else --- probably varlena
 You win, how can I pay this bet? :) Very very thanks, I was looking for the error in the wrong place! It was
so simple and works!
 But still have another problem, may be related with my output
functions!?!?  I still get an error while doing a select with order by clause! Any other
good bet?
The error is:
ERROR: cache lookup failed for operator......

 Thanks in advance!