From: | tolik(at)icomm(dot)ru (Anatoly K(dot) Lasareff) |
---|---|
To: | Adriaan Joubert <a(dot)joubert(at)albourne(dot)com> |
Cc: | Postgres-General <pgsql-general(at)postgreSQL(dot)org> |
Subject: | Re: [GENERAL] Text function problem |
Date: | 1999-06-02 10:04:59 |
Message-ID: | 87pv3encj8.fsf@tolikus.hq.aaanet.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>>>>> "AJ" == Adriaan Joubert <a(dot)joubert(at)albourne(dot)com> writes:
AJ> Hi,
AJ> I've been adding some bit functions to postgres and this works fine,
AJ> until I tried to construct a function that returns 8 bits as a string,
AJ> e.g. 4 as 00000100. I constructed the function with the help of the
AJ> programmer manual.
AJ> Now I have the following problem on Friday's snapshot: the first time I
AJ> select an integer as bitstring it works fine, but the second time I get
AJ> a segflt. So I'm evidently missing something somewhere. I'd appreciate
AJ> it if somebody could tell me what I'm doing wrong.
AJ> I'm getting (from the backend)
. . .
skip
. . .
AJ> text * bout (int a) {
AJ> int32 new_text_size = VARHDRSZ + sizeof(char)*8;
AJ> text *new_text = (text *) palloc(new_text_size);
AJ> int i;
AJ> for (i=0; i<8; i++)
AJ> VARDATA(new_text)[i] = (a>>(7-i))%2 ? '1' : '0';
AJ> return new_text;
AJ> }
You do not set length of data in *new_text. You must write about this:
---------------------------------
text * bout (int a) {
int32 new_text_size = VARHDRSZ + sizeof(char)*8;
text *new_text = (text *) palloc(new_text_size);
int i;
VARSIZE(new_text) = new_text_size; /* !!!!! */
for (i=0; i<8; i++)
VARDATA(new_text)[i] = (a>>(7-i))%2 ? '1' : '0';
return new_text;
}
---------------------------------
More: it'll be better if you change 'int' to 'int4' data type in your
nexts.
--
Anatoly K. Lasareff Email: tolik(at)icomm(dot)ru
Senior programmer
From | Date | Subject | |
---|---|---|---|
Next Message | Stuart Rison | 1999-06-02 15:16:36 | RE: [GENERAL][SQL] 'denormalising' with a select |
Previous Message | Natalya S. Makushina | 1999-06-02 07:40:20 | Re: [GENERAL] ' syntax (using PHP3) |