Skip site navigation (1) Skip section navigation (2)

Re: user defined type

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: (view raw, whole thread or download thread mbox)
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];

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);



In response to


pgsql-novice by date

Next:From: Michael FuhrDate: 2004-11-10 18:30:05
Subject: Re: user defined type
Previous:From: Vishal Kashyap @ [Sai Hertz And Control Systems]Date: 2004-11-10 02:47:03
Subject: Re: VACUUM ANALYZE : Is this a time consuming procedure?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group