Re: atttypmod of 0

Started by Zeugswetter Andreas DBTalmost 28 years ago15 messages
#1Zeugswetter Andreas DBT
Andreas.Zeugswetter@telecom.at

This time it's during the parser (gdb told me). varcharin()
is called with a atttypmod of 0 causing a palloc() of 0
bytes. How should a VARCHAR type whithout a specified length
behave? Is this type 1 character or a variable size up to
4096?

I thought we fixed this on Feb 3. look at
parse_expr.c line 104: it should read:
if (con->typename != NULL)
! result = parser_typecast(val,
con->typename, -1);
else

I think all funcs calling with atttypmod = 0 are allways wrong, should
be -1.
or a number > 0 (or 4 if atttypmod includes the VARHDRSZ don't know)

Andreas

#2Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Zeugswetter Andreas DBT (#1)
Re: [HACKERS] Re: atttypmod of 0

This time it's during the parser (gdb told me). varcharin()
is called with a atttypmod of 0 causing a palloc() of 0
bytes. How should a VARCHAR type whithout a specified length
behave? Is this type 1 character or a variable size up to
4096?

I thought we fixed this on Feb 3. look at
parse_expr.c line 104: it should read:
if (con->typename != NULL)
! result = parser_typecast(val,
con->typename, -1);
else

I think all funcs calling with atttypmod = 0 are allways wrong, should
be -1.
or a number > 0 (or 4 if atttypmod includes the VARHDRSZ don't know)

Andreas

Yes, we did, but now I fixed varcharin, and bpcharin to test for
atttypmod of 0 and do the right thing, I think. If we need to make the
default atttypmod value -1, then we can change it back. Let me know if
the current fix does not work.

Should I make atttypmod default to -1?

--
Bruce Momjian
maillist@candle.pha.pa.us

#3Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Zeugswetter Andreas DBT (#1)
Re: [HACKERS] Re: atttypmod of 0

This time it's during the parser (gdb told me). varcharin()
is called with a atttypmod of 0 causing a palloc() of 0
bytes. How should a VARCHAR type whithout a specified length
behave? Is this type 1 character or a variable size up to
4096?

I thought we fixed this on Feb 3. look at
parse_expr.c line 104: it should read:
if (con->typename != NULL)
! result = parser_typecast(val,
con->typename, -1);
else

I think all funcs calling with atttypmod = 0 are allways wrong, should
be -1.
or a number > 0 (or 4 if atttypmod includes the VARHDRSZ don't know)

It does include the VARHDRSZ.

--
Bruce Momjian
maillist@candle.pha.pa.us

#4Noname
jwieck@debis.com
In reply to: Bruce Momjian (#3)
Re: [HACKERS] Re: atttypmod of 0

This time it's during the parser (gdb told me). varcharin()
is called with a atttypmod of 0 causing a palloc() of 0
bytes. How should a VARCHAR type whithout a specified length
behave? Is this type 1 character or a variable size up to
4096?

I thought we fixed this on Feb 3. look at
parse_expr.c line 104: it should read:
if (con->typename != NULL)
! result = parser_typecast(val,
con->typename, -1);
else

I think all funcs calling with atttypmod = 0 are allways wrong, should
be -1.
or a number > 0 (or 4 if atttypmod includes the VARHDRSZ don't know)

It does include the VARHDRSZ.

So the right check would be "atttypmod > 4" instead of "> 0"
But fixing all the other places to use one and the same
value (0 or -1) would be a good idea.

--
Bruce Momjian
maillist@candle.pha.pa.us

Until later, Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #

#5Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Noname (#4)
Re: [HACKERS] Re: atttypmod of 0

It does include the VARHDRSZ.

So the right check would be "atttypmod > 4" instead of "> 0"
But fixing all the other places to use one and the same
value (0 or -1) would be a good idea.

I already have. 0 is the default, but I can change it.

--
Bruce Momjian
maillist@candle.pha.pa.us

#6Zeugswetter Andreas DBT
Andreas.Zeugswetter@telecom.at
In reply to: Bruce Momjian (#5)
AW: [HACKERS] Re: atttypmod of 0

Yes, I think to change atttypmod to default to -1 would be the right
thing,
since the empty string '' really has a length of 0,
We could think of -1 as: We don't know how long this field will be.
0 would mean the field has 0 bytes.

Andreas

Show quoted text

This time it's during the parser (gdb told me). varcharin()
is called with a atttypmod of 0 causing a palloc() of 0
bytes. How should a VARCHAR type whithout a specified length
behave? Is this type 1 character or a variable size up to
4096?

I thought we fixed this on Feb 3. look at
parse_expr.c line 104: it should read:
if (con->typename != NULL)
! result =

parser_typecast(val,

con->typename, -1);
else

I think all funcs calling with atttypmod = 0 are allways wrong,

should

be -1.
or a number > 0 (or 4 if atttypmod includes the VARHDRSZ don't know)

Andreas

Yes, we did, but now I fixed varcharin, and bpcharin to test for
atttypmod of 0 and do the right thing, I think. If we need to make
the
default atttypmod value -1, then we can change it back. Let me know
if
the current fix does not work.

Should I make atttypmod default to -1?

--
Bruce Momjian
maillist@candle.pha.pa.us

#7Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Zeugswetter Andreas DBT (#6)
Re: AW: [HACKERS] Re: atttypmod of 0

Yes, I think to change atttypmod to default to -1 would be the right
thing,
since the empty string '' really has a length of 0,
We could think of -1 as: We don't know how long this field will be.
0 would mean the field has 0 bytes.

Field has varlena == 4, so zero is not possible, but I could still
change to -1 for clarity.

--
Bruce Momjian
maillist@candle.pha.pa.us

#8Zeugswetter Andreas DBT
Andreas.Zeugswetter@telecom.at
In reply to: Bruce Momjian (#7)
AW: AW: [HACKERS] Re: atttypmod of 0

I guess I don't have a strong opinion on that. Since atttypmod is also
intended for
decimal and others, I think the default has to be type specific anyway,
like 0 digits after the comma for decimal.
I would prefer an atttypmod that does not include the VARHDRSZ for
varchar though.
Then it would simply be the max length (better for humans reading the
system catalog).
The default of zero would still be no problem I guess, since max zero
length is still nonsense.

Andreas

Show quoted text

Yes, I think to change atttypmod to default to -1 would be the right
thing,
since the empty string '' really has a length of 0,
We could think of -1 as: We don't know how long this field will be.
0 would mean the field has 0 bytes.

Field has varlena == 4, so zero is not possible, but I could still
change to -1 for clarity.

#9Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Zeugswetter Andreas DBT (#8)
Re: AW: AW: [HACKERS] Re: atttypmod of 0

I guess I don't have a strong opinion on that. Since atttypmod is also
intended for
decimal and others, I think the default has to be type specific anyway,
like 0 digits after the comma for decimal.
I would prefer an atttypmod that does not include the VARHDRSZ for
varchar though.
Then it would simply be the max length (better for humans reading the
system catalog).
The default of zero would still be no problem I guess, since max zero
length is still nonsense.

I indented to change it to -1 when we start using atttypmod for more
types that just char() and varchar().

--
Bruce Momjian
maillist@candle.pha.pa.us

#10Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Zeugswetter Andreas DBT (#6)
Re: AW: [HACKERS] Re: atttypmod of 0

Yes, I think to change atttypmod to default to -1 would be the right
thing,
since the empty string '' really has a length of 0,
We could think of -1 as: We don't know how long this field will be.
0 would mean the field has 0 bytes.

Do people want atttypmod at -1 at this time? It will require a
dump/reload.

--
Bruce Momjian
maillist@candle.pha.pa.us

#11Thomas G. Lockhart
lockhart@alumni.caltech.edu
In reply to: Bruce Momjian (#10)
Re: AW: [HACKERS] Re: atttypmod of 0

Yes, I think to change atttypmod to default to -1 would be the right
thing,
since the empty string '' really has a length of 0,
We could think of -1 as: We don't know how long this field will be.
0 would mean the field has 0 bytes.

Do people want atttypmod at -1 at this time? It will require a
dump/reload.

If it fixes problems, now is the time :)

#12Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Thomas G. Lockhart (#11)
Re: AW: [HACKERS] Re: atttypmod of 0

Yes, I think to change atttypmod to default to -1 would be the right
thing,
since the empty string '' really has a length of 0,
We could think of -1 as: We don't know how long this field will be.
0 would mean the field has 0 bytes.

Do people want atttypmod at -1 at this time? It will require a
dump/reload.

If it fixes problems, now is the time :)

Well, right now, since it is not being used from anything by char() and
varchar(), it is not a problem. But it will have to be changed when we
use it for other types.

So do we change it now?

--
Bruce Momjian
maillist@candle.pha.pa.us

#13Thomas G. Lockhart
lockhart@alumni.caltech.edu
In reply to: Bruce Momjian (#12)
Re: AW: [HACKERS] Re: atttypmod of 0

Yes, I think to change atttypmod to default to -1 would be the right
thing,
since the empty string '' really has a length of 0,
We could think of -1 as: We don't know how long this field will be.
0 would mean the field has 0 bytes.

Do people want atttypmod at -1 at this time? It will require a
dump/reload.

If it fixes problems, now is the time :)

Well, right now, since it is not being used from anything by char() and
varchar(), it is not a problem. But it will have to be changed when we
use it for other types.

So do we change it now?

If it make things more self-consistant, now is the time :)

I would consider all of this related to or a followup on the char/varchar
work done earlier.

- Tom

#14Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Thomas G. Lockhart (#13)
Re: AW: [HACKERS] Re: atttypmod of 0

So do we change it now?

If it make things more self-consistant, now is the time :)

I would consider all of this related to or a followup on the char/varchar
work done earlier.

OK

--
Bruce Momjian
maillist@candle.pha.pa.us

#15Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Bruce Momjian (#10)
Re: AW: [HACKERS] Re: atttypmod of 0

Yes, I think to change atttypmod to default to -1 would be the right
thing,
since the empty string '' really has a length of 0,
We could think of -1 as: We don't know how long this field will be.
0 would mean the field has 0 bytes.

Do people want atttypmod at -1 at this time? It will require a
dump/reload.

OK, atttypmod now defaults to -1. Initdb everyone.

--
Bruce Momjian
maillist@candle.pha.pa.us