Return-Path: postgres@csr.lbl.gov 
Delivery-Date: Sun, 18 Jul 93 10:55:48 PDT
Return-Path: postgres@csr.lbl.gov
Received: from csr.lbl.gov by postgres.Berkeley.EDU (5.61/1.29)
	id AA03538; Sun, 18 Jul 93 10:55:46 -0700
Received: from segev.lbl.gov by csr.lbl.gov (4.1/1.39)
	id AA04765; Sun, 18 Jul 93 11:01:17 PDT
Date: Sun, 18 Jul 93 11:01:17 PDT
From: postgres@csr.lbl.gov (Ellen Rose)
Message-Id: <9307181801.AA04765@csr.lbl.gov>
To: aoki@postgres.berkeley.edu
Subject: User Types


I am still getting errors when I try to append data of type
TS_string:


define function TS_string_in (language="c",returntype=TS_string) arg is (char16) as
"/usr/postgres/include/adt/TS_string.o"  
NOTICE:Jul 18 10:14:51:ProcedureDefine: return type 'TS_string' not yet
defined
DEFINE

define function TS_string_out (language="c",returntype=char16) arg is
(TS_string) as "/usr/postgres/include/adt/TS_string.o"   
DEFINE

define type TS_string (internallength = 28, input=TS_string_in,
output=TS_string_out)  
DEFINE

create META_TYPES ( Type_Name=char16, Type_Description=TS_string )  
CREATE

append META_TYPES (Type_Name="PERSON", Type_Description="(\\"Individuals\\",\\"now\\", \\"[now,]\\")"::TS_string)  

WARN:Jul 18 10:34:12:parser: syntax error at or near "Individuals"



****************

Also, if I wanted to change the type of the first of the 3 parts of the TS_string
structure from char16 to text does that make internallength = variable when
I define the type?

Also, it says we can't use pointers in defining internal representations of
user types so how could I make a member of a structure a text type if I
can't use (text *) the C type representation for postgres text fields
according to page 71 of the reference manual?


/Ellen


******************** TS_string.c follows *******************************
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "tmp/c.h"
#include "tmp/libpq-fe.h"
#include "utils/geo-decls.h"
#include "utils/palloc.h"
#include "utils/builtins.h"

typedef struct {
	Char16			string;
	AbsoluteTime	tt;
	TimeInterval	vt;
} TS_string;

TS_string	*TS_string_in();
char	*TS_string_out();

#define LDELIM	'('
#define RDELIM	')'
#define NARGS	3

TS_string *
TS_string_in(str)
char	*str;
{
	char	*strcpy(), *p,
		*coord[NARGS], buf2[1000];
	int	i;
	TS_string	*result;

	if (str == NULL)
		return(NULL);
	for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
		if (*p == ',' || (*p == LDELIM && !i))
			coord[i++] = p + 1;
	if (i < NARGS - 1)
		return(NULL);
	result = (TS_string *) palloc(sizeof(TS_string));
	result->string = (Char16)coord[0];
	result->tt = (AbsoluteTime)coord[1];
	result->vt = (TimeInterval)coord[2];
	sprintf(buf2, "TS_string_in: read (%s,%s,%s)\n",
	(char *)result->string, (char *)result->tt, (char *)result->vt);
	return(result);
}

char *
TS_string_out(ts_string)
TS_string	*ts_string;
{
	char	*result;

	if (ts_string == NULL)
		return(NULL);

	result = (char *) palloc(sizeof(AbsoluteTime)+sizeof(TimeInterval)+sizeof(text *) );
	(void) sprintf(result, "(%s,%s,%s)", ts_string->string, ts_string->tt, ts_string->vt);
	return(result);
}

