From: | Kjetil Haaland <kjetil(dot)haaland(at)student(dot)uib(dot)no> |
---|---|
To: | Michael Fuhr <mike(at)fuhr(dot)org> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: user defined type |
Date: | 2004-11-10 13:37:49 |
Message-ID: | 200411101437.49058.kjetil.haaland@student.uib.no |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
hello again
Thanks to you i have no managed to store a value and a string of variable
length in the structure. I thought it would be easy to expand it to two
strings and a value, by doing it the same way, but that didn't work out. When
i insert something into the type this is what happends:
1) the first string in the structure has one character( or the size of the
table that holds the first string) from the first string i gave, a blank
space and the second string i gave.
2)the second string is correct - has the second string i gave.
Is there anyway to have two or more strings in one type or do i have to save
them both in one string? This is my type and the in function so far:
typedef struct alignres {
int32 length;
int value;
char fstring[1];
char sstring[1];
}alignres;
Datum alignres_in(PG_FUNCTION_ARGS) {
char *in = PG_GETARG_CSTRING(0);
char *workstr = pstrdup(in);
char *svalue = NULL;
char *first = NULL;
char *second = NULL;
svalue = strtok(workstr, ", ");
first = strtok(NULL, ", ");
second = strtok(NULL, ")");
int value = atoi(++svalue);
alignres *result;
result = (alignres *) palloc(sizeof(*result)+strlen(in));
result->value = value;
strcpy(result->fstring, first);
strcpy(result->sstring, second);
result->length=sizeof(*result)+strlen(result->fstring)+strlen(result->sstring);
PG_RETURN_POINTER(result);
}
-Kjetil
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2004-11-10 18:30:05 | Re: user defined type |
Previous Message | Vishal Kashyap @ [Sai Hertz And Control Systems] | 2004-11-10 02:47:03 | Re: VACUUM ANALYZE : Is this a time consuming procedure? |