Re: user defined type

Поиск
Список
Период
Сортировка
От Kjetil Haaland
Тема Re: user defined type
Дата
Msg-id 200411101437.49058.kjetil.haaland@student.uib.no
обсуждение исходный текст
Ответ на Re: user defined type  (Michael Fuhr <mike@fuhr.org>)
Ответы Re: user defined type
Список 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

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Vishal Kashyap @ [Sai Hertz And Control Systems]"
Дата:
Сообщение: Re: VACUUM ANALYZE : Is this a time consuming procedure?
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: user defined type