Folks,
Hereby the version 2.0 of the uuid datatype patch with modifications
commented by Neil.
- the uuid.h has been cleaned.
the declarations have been moved to uuid.c
- the text_uuid() and varchar_uuid() have been refactored.
- all uuid explicit functions are moved to uuid.c and made local.
* this patch has been tested on 8.3devel, the snapshot of 25-Jan-07
* this patch uses 28 new oids. I have assigned the oids from 2950.
If you need to change the oids, do not do this manually. I have a script
that does that. Just provide me 28 unused oids and I will generate a new
patch.
Please provide comments.
Regards,
Gevik
###############################################################
# Patch created by PostgreSQL Patch Generator 1.0
# Written by Gevik Babakhani 2007 (BSD)
#
# Apply this patch:
# cd ./mydir.../pgsql/
# patch -p0 < this.patch.file.diff
#
# Date created: Thu, 25 Jan 2007 22:21:21 +0100
#
# New files:
# ./src/backend/utils/adt/uuid.c
# ./src/include/utils/uuid.h
# ./src/test/regress/expected/uuid.out
# ./src/test/regress/sql/uuid.sql
# Modified files:
# ./src/backend/utils/adt/Makefile
# ./src/include/catalog/pg_amop.h
# ./src/include/catalog/pg_amproc.h
# ./src/include/catalog/pg_cast.h
# ./src/include/catalog/pg_opclass.h
# ./src/include/catalog/pg_operator.h
# ./src/include/catalog/pg_opfamily.h
# ./src/include/catalog/pg_proc.h
# ./src/include/catalog/pg_type.h
# ./src/include/utils/builtins.h
# ./src/test/regress/parallel_schedule
# ./src/test/regress/serial_schedule
##############################################################
*** ./src/backend/utils/adt/Makefile.orig 2007-01-24 16:35:05.000000000 +0100
--- ./src/backend/utils/adt/Makefile 2007-01-24 16:37:12.000000000 +0100
***************
*** 15,21 ****
endif
endif
! OBJS = acl.o arrayfuncs.o array_userfuncs.o arrayutils.o bool.o \
cash.o char.o date.o datetime.o datum.o domains.o \
float.o format_type.o \
geo_ops.o geo_selfuncs.o int.o int8.o like.o lockfuncs.o \
--- 15,21 ----
endif
endif
! OBJS = uuid.o acl.o arrayfuncs.o array_userfuncs.o arrayutils.o bool.o \
cash.o char.o date.o datetime.o datum.o domains.o \
float.o format_type.o \
geo_ops.o geo_selfuncs.o int.o int8.o like.o lockfuncs.o \
*** ./src/backend/utils/adt/uuid.c.orig 1970-01-01 01:00:00.000000000 +0100
--- ./src/backend/utils/adt/uuid.c 2007-01-24 17:54:54.000000000 +0100
***************
*** 0 ****
--- 1,271 ----
+ /*-------------------------------------------------------------------------
+ *
+ * uuid.h
+ * Header file for the SQL datatypes UUID.
+ *
+ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ #include "postgres.h"
+ #include "access/hash.h"
+ #include "libpq/pqformat.h"
+ #include "utils/builtins.h"
+ #include "utils/uuid.h"
+
+ /* declarations */
+
+ static void create_uuiddata_from_string(const char* source,unsigned char *data);
+ static bool parse_uuid_string(const char* fmt,const char* source,unsigned char* data);
+ static void create_string_form_uuid_data(const char* fmt,const char *data,char *uuid_str);
+ static int32 uuid_internal_cmp(uuid_t *arg1,uuid_t *arg2);
+ static Datum cast_text_to_uuid(text *input);
+
+ /*
+ * function handles input for the uuid datatype
+ */
+ Datum uuid_in(PG_FUNCTION_ARGS)
+ {
+ uuid_t *uuid;
+ uint8 data[UUID_LEN];
+
+ char *uuid_str = PG_GETARG_CSTRING(0);
+
+ create_uuiddata_from_string(uuid_str,data);
+
+ uuid = (uuid_t *) palloc(sizeof(uuid_t));
+ memcpy(uuid->data,data,UUID_LEN);
+
+ PG_RETURN_UUID_P(uuid);
+ }
+
+ /*
+ * function handles output for the uuid datatype
+ */
+ Datum uuid_out(PG_FUNCTION_ARGS)
+ {
+ uuid_t *uuid = (uuid_t *) PG_GETARG_POINTER(0);
+
+ char *uuid_str;
+
+ uuid_str = (char *)palloc(PRINT_SIZE);
+ create_string_form_uuid_data(UUID_FMT1,uuid->data,uuid_str);
+
+ PG_RETURN_CSTRING(uuid_str);
+ }
+
+ /* uuid binary receive handler */
+ Datum uuid_recv(PG_FUNCTION_ARGS)
+ {
+ uuid_t *uuid;
+ StringInfo buffer = (StringInfo) PG_GETARG_POINTER(0);
+
+ uuid = (uuid_t *)palloc(UUID_LEN);
+ memcpy(uuid->data,pq_getmsgbytes(buffer,UUID_LEN),UUID_LEN);
+ PG_RETURN_POINTER(uuid);
+ }
+
+ /* uuid binary send handler */
+ Datum uuid_send(PG_FUNCTION_ARGS)
+ {
+ uuid_t *uuid = PG_GETARG_UUID_P(0);
+ StringInfoData buffer;
+
+ pq_begintypsend(&buffer);
+ pq_sendbytes(&buffer,uuid->data,UUID_LEN);
+ PG_RETURN_BYTEA_P(pq_endtypsend(&buffer));
+ }
+
+ /* handler for < operator */
+ Datum uuid_lt(PG_FUNCTION_ARGS)
+ {
+ bool result;
+ uuid_t *arg1 = PG_GETARG_UUID_P(0);
+ uuid_t *arg2 = PG_GETARG_UUID_P(1);
+
+ result = uuid_internal_cmp(arg1,arg2) < 0;
+
+ PG_RETURN_BOOL(result);
+ }
+
+ /* handler for <= operator */
+ Datum uuid_le(PG_FUNCTION_ARGS)
+ {
+ bool result;
+ uuid_t *arg1 = PG_GETARG_UUID_P(0);
+ uuid_t *arg2 = PG_GETARG_UUID_P(1);
+
+ result = uuid_internal_cmp(arg1,arg2) <= 0;
+
+ PG_RETURN_BOOL(result);
+ }
+
+
+ /* handler for = operator */
+ Datum uuid_eq(PG_FUNCTION_ARGS)
+ {
+ bool result;
+ uuid_t *arg1 = PG_GETARG_UUID_P(0);
+ uuid_t *arg2 = PG_GETARG_UUID_P(1);
+
+ result = uuid_internal_cmp(arg1,arg2) == 0;
+
+ PG_RETURN_BOOL(result);
+ }
+
+ /* handler for >= operator */
+ Datum uuid_ge(PG_FUNCTION_ARGS)
+ {
+ bool result;
+ uuid_t *arg1 = PG_GETARG_UUID_P(0);
+ uuid_t *arg2 = PG_GETARG_UUID_P(1);
+
+ result = uuid_internal_cmp(arg1,arg2) >= 0;
+
+ PG_RETURN_BOOL(result);
+ }
+
+ /* handler for > operator */
+ Datum uuid_gt(PG_FUNCTION_ARGS)
+ {
+ bool result;
+ uuid_t *arg1 = PG_GETARG_UUID_P(0);
+ uuid_t *arg2 = PG_GETARG_UUID_P(1);
+
+ result = uuid_internal_cmp(arg1,arg2) > 0;
+
+ PG_RETURN_BOOL(result);
+ }
+
+
+ /* handler for <> operator */
+ Datum uuid_ne(PG_FUNCTION_ARGS)
+ {
+ bool result;
+ uuid_t *arg1 = PG_GETARG_UUID_P(0);
+ uuid_t *arg2 = PG_GETARG_UUID_P(1);
+
+ result = uuid_internal_cmp(arg1,arg2) != 0;
+
+ PG_RETURN_BOOL(result);
+ }
+
+ /* handler for btree index operator */
+ Datum uuid_cmp(PG_FUNCTION_ARGS)
+ {
+ int32 result;
+
+ uuid_t *arg1 = PG_GETARG_UUID_P(0);
+ uuid_t *arg2 = PG_GETARG_UUID_P(1);
+
+ result = uuid_internal_cmp(arg1,arg2);
+ PG_RETURN_INT32(result);
+ }
+
+ /* hash index support */
+ Datum uuid_hash(PG_FUNCTION_ARGS)
+ {
+ uuid_t *key = PG_GETARG_UUID_P(0);
+ return hash_any((unsigned char*)key,sizeof(uuid_t));
+ }
+
+ /* base function to cast varchat/text to uuid */
+ Datum cast_text_to_uuid(text *input)
+ {
+ int length;
+ char* str;
+ Datum result;
+
+ length = (VARSIZE(input) - VARHDRSZ);
+ str = palloc(length + 1);
+ memcpy(str, VARDATA(input), length);
+ *(str + length) = '\0';
+
+ result = DirectFunctionCall1(uuid_in, CStringGetDatum(str));
+ pfree(str);
+ return result;
+
+ }
+
+ /* cast varchar to uuid */
+ Datum varchar_uuid(PG_FUNCTION_ARGS)
+ {
+ VarChar* input = PG_GETARG_VARCHAR_P(0);
+ return cast_text_to_uuid(input);
+ }
+
+ /* cast text to uuid */
+ Datum text_uuid(PG_FUNCTION_ARGS)
+ {
+ text* input = PG_GETARG_TEXT_P(0);
+ return cast_text_to_uuid(input);
+ }
+
+ /* cast uuid to varchar */
+ Datum uuid_varchar(PG_FUNCTION_ARGS)
+ {
+ uuid_t *uuid = PG_GETARG_UUID_P(0);
+ Datum result;
+ Datum uuid_str = DirectFunctionCall1(uuid_out, UUIDPGetDatum(uuid));
+
+ result = DirectFunctionCall3(varcharin, uuid_str,
+ ObjectIdGetDatum(0), Int32GetDatum(-1));
+ return result;
+ }
+
+ /* internal uuid compare function */
+ int32 uuid_internal_cmp(uuid_t *arg1,uuid_t *arg2)
+ {
+ return memcmp(arg1->data,arg2->data,UUID_LEN);
+ }
+
+ /* string to uuid convertor by various format types*/
+ void create_uuiddata_from_string(const char* source,unsigned char *data)
+ {
+ if(!parse_uuid_string(UUID_FMT1,source,data))
+ {
+ if(!parse_uuid_string(UUID_FMT2,source,data))
+ {
+ if(!parse_uuid_string(UUID_FMT3,source,data))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+ errmsg("invalid input syntax for uuid: \"%s\"",
+ source)));
+ }
+ }
+ }
+ }
+
+ /* create a string representation of the uuid */
+ void create_string_form_uuid_data(const char* fmt,const char *data,char *uuid_str)
+ {
+ snprintf(uuid_str, PRINT_SIZE,fmt,
+ data[0],data[1],data[2],data[3],data[4],
+ data[5],data[6],data[7],data[8],data[9],
+ data[10],data[11],data[12],data[13],
+ data[14],data[15]);
+ }
+
+ /* parse the uuid string to a format and return true if okay */
+ bool parse_uuid_string(const char* fmt,const char* source,unsigned char* data)
+ {
+ int result = sscanf(source,fmt,&data[0],&data[1],&data[2],&data[3],&data[4],
+ &data[5],&data[6],&data[7],&data[8],&data[9],&data[10],&data[11],
+ &data[12],&data[13],&data[14],&data[15]);
+
+ return result == 16;
+ }
+
+
+ /* cast uuid to text */
+ Datum uuid_text(PG_FUNCTION_ARGS)
+ {
+ uuid_t *uuid = PG_GETARG_UUID_P(0);
+ Datum result;
+ Datum uuid_str = DirectFunctionCall1(uuid_out, UUIDPGetDatum(uuid));
+
+ result = DirectFunctionCall1(textin, uuid_str);
+ return result;
+ }
*** ./src/include/catalog/pg_amop.h.orig 2007-01-24 16:35:03.000000000 +0100
--- ./src/include/catalog/pg_amop.h 2007-01-25 20:58:01.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+
+
/*-------------------------------------------------------------------------
*
* pg_amop.h
***************
*** 614,618 ****
--- 616,631 ----
DATA(insert ( 2745 2277 2277 2 f 2751 2742 ));
DATA(insert ( 2745 2277 2277 3 t 2752 2742 ));
DATA(insert ( 2745 2277 2277 4 t 1070 2742 ));
+ /* uuid */
+ /* hash */
+ DATA(insert (2969 2950 2950 1 f 2972 405 ));
+ /* btree */
+ DATA(insert (2968 2950 2950 1 f 2974 403 ));
+ DATA(insert (2968 2950 2950 2 f 2976 403 ));
+ DATA(insert (2968 2950 2950 3 f 2972 403 ));
+ DATA(insert (2968 2950 2950 4 f 2977 403 ));
+ DATA(insert (2968 2950 2950 5 f 2975 403 ));
+
#endif /* PG_AMOP_H */
+
*** ./src/include/catalog/pg_amproc.h.orig 2007-01-24 16:35:03.000000000 +0100
--- ./src/include/catalog/pg_amproc.h 2007-01-25 20:58:01.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+
+
/*-------------------------------------------------------------------------
*
* pg_amproc.h
***************
*** 298,302 ****
--- 300,311 ----
DATA(insert ( 2745 1025 1025 2 2743 ));
DATA(insert ( 2745 1025 1025 3 2743 ));
DATA(insert ( 2745 1025 1025 4 2744 ));
+ /* uuid */
+ /* btree */
+ DATA(insert (2968 2950 2950 1 2960 ));
+ /* hash */
+ DATA(insert (2969 2950 2950 1 2963 ));
+
#endif /* PG_AMPROC_H */
+
*** ./src/include/catalog/pg_cast.h.orig 2007-01-24 16:35:03.000000000 +0100
--- ./src/include/catalog/pg_cast.h 2007-01-25 20:58:01.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+
+
/*-------------------------------------------------------------------------
*
* pg_cast.h
***************
*** 200,205 ****
--- 202,213 ----
/*
* Datetime category
*/
+ /* uuid */
+ DATA(insert (25 2950 2964 a ));
+ DATA(insert (2950 25 2965 a ));
+ DATA(insert (1043 2950 2966 a ));
+ DATA(insert (2950 1043 2967 a ));
+
DATA(insert ( 702 1082 1179 a ));
DATA(insert ( 702 1083 1364 a ));
DATA(insert ( 702 1114 2023 i ));
***************
*** 398,400 ****
--- 406,409 ----
DATA(insert ( 1700 1700 1703 i ));
#endif /* PG_CAST_H */
+
*** ./src/include/catalog/pg_opclass.h.orig 2007-01-24 16:35:03.000000000 +0100
--- ./src/include/catalog/pg_opclass.h 2007-01-25 20:58:01.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+
+
/*-------------------------------------------------------------------------
*
* pg_opclass.h
***************
*** 200,204 ****
--- 202,213 ----
DATA(insert ( 2742 _money_ops PGNSP PGUID 2745 791 t 790 ));
DATA(insert ( 2742 _reltime_ops PGNSP PGUID 2745 1024 t 703 ));
DATA(insert ( 2742 _tinterval_ops PGNSP PGUID 2745 1025 t 704 ));
+ /* uuid */
+ /* btree */
+ DATA(insert OID = 2970 (403 uuid_ops PGNSP PGUID 2968 2950 t 0 ));
+ /* hash */
+ DATA(insert OID = 2971 (405 uuid_ops PGNSP PGUID 2969 2950 t 0 ));
+
#endif /* PG_OPCLASS_H */
+
*** ./src/include/catalog/pg_operator.h.orig 2007-01-24 16:35:03.000000000 +0100
--- ./src/include/catalog/pg_operator.h 2007-01-25 20:58:01.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+
+
/*-------------------------------------------------------------------------
*
* pg_operator.h
***************
*** 895,900 ****
--- 897,910 ----
DATA(insert OID = 2876 ( "@" PGNSP PGUID b f f 601 603 16 0 0 on_sb - - ));
DATA(insert OID = 2877 ( "~" PGNSP PGUID b f f 1034 1033 16 0 0 aclcontains - - ));
+ /* uuid */
+ DATA(insert OID = 2972 ("=" PGNSP PGUID b t t 2950 2950 16 2972 2973 uuid_eq eqsel eqjoinsel ));
+ DATA(insert OID = 2973 ("<>" PGNSP PGUID b f f 2950 2950 16 2973 2972 uuid_ne neqsel neqjoinsel ));
+ DATA(insert OID = 2974 ("<" PGNSP PGUID b f f 2950 2950 16 2975 2977 uuid_lt scalarltsel scalarltjoinsel ));
+ DATA(insert OID = 2975 (">" PGNSP PGUID b f f 2950 2950 16 2974 2976 uuid_gt scalargtsel scalargtjoinsel ));
+ DATA(insert OID = 2976 ("<=" PGNSP PGUID b f f 2950 2950 16 2977 2975 uuid_le scalarltsel scalarltjoinsel ));
+ DATA(insert OID = 2977 (">=" PGNSP PGUID b f f 2950 2950 16 2976 2974 uuid_ge scalargtsel scalargtjoinsel ));
+
/*
* function prototypes
***************
*** 912,914 ****
--- 922,925 ----
bool canHash);
#endif /* PG_OPERATOR_H */
+
*** ./src/include/catalog/pg_opfamily.h.orig 2007-01-24 16:35:03.000000000 +0100
--- ./src/include/catalog/pg_opfamily.h 2007-01-25 20:58:01.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+
+
/*-------------------------------------------------------------------------
*
* pg_opfamily.h
***************
*** 134,138 ****
--- 136,145 ----
DATA(insert OID = 2594 ( 783 poly_ops PGNSP PGUID ));
DATA(insert OID = 2595 ( 783 circle_ops PGNSP PGUID ));
DATA(insert OID = 2745 ( 2742 array_ops PGNSP PGUID ));
+ /* uuid */
+ DATA(insert OID = 2968 (403 uuid_ops PGNSP PGUID ));
+ DATA(insert OID = 2969 (405 uuid_ops PGNSP PGUID ));
+
#endif /* PG_OPFAMILY_H */
+
*** ./src/include/catalog/pg_proc.h.orig 2007-01-24 16:35:03.000000000 +0100
--- ./src/include/catalog/pg_proc.h 2007-01-25 20:58:01.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+
+
/*-------------------------------------------------------------------------
*
* pg_proc.h
***************
*** 4046,4051 ****
--- 4048,4087 ----
DATA(insert OID = 2901 ( xmlagg PGNSP PGUID 12 1 0 t f f f i 1 142 "142" _null_ _null_ _null_ aggregate_dummy - _null_ ));
DESCR("concatenate XML values");
+ /* uuid */
+ DATA(insert OID = 2952 (uuid_in PGNSP PGUID 12 1 0 f f t f i 1 2950 "2275" _null_ _null_ _null_ uuid_in - _null_ ));
+ DESCR("I/O");
+ DATA(insert OID = 2953 (uuid_out PGNSP PGUID 12 1 0 f f t f i 1 2275 "2950" _null_ _null_ _null_ uuid_out - _null_ ));
+ DESCR("I/O");
+ DATA(insert OID = 2954 (uuid_lt PGNSP PGUID 12 1 0 f f t f i 2 16 "2950 2950" _null_ _null_ _null_ uuid_lt - _null_ ));
+ DESCR("less-than");
+ DATA(insert OID = 2955 (uuid_le PGNSP PGUID 12 1 0 f f t f i 2 16 "2950 2950" _null_ _null_ _null_ uuid_le - _null_ ));
+ DESCR("less-than-or-equal");
+ DATA(insert OID = 2956 (uuid_eq PGNSP PGUID 12 1 0 f f t f i 2 16 "2950 2950" _null_ _null_ _null_ uuid_eq - _null_ ));
+ DESCR("equal");
+ DATA(insert OID = 2957 (uuid_ge PGNSP PGUID 12 1 0 f f t f i 2 16 "2950 2950" _null_ _null_ _null_ uuid_ge - _null_ ));
+ DESCR("greater-than-or-equal");
+ DATA(insert OID = 2958 (uuid_gt PGNSP PGUID 12 1 0 f f t f i 2 16 "2950 2950" _null_ _null_ _null_ uuid_gt - _null_ ));
+ DESCR("greater-than");
+ DATA(insert OID = 2959 (uuid_ne PGNSP PGUID 12 1 0 f f t f i 2 16 "2950 2950" _null_ _null_ _null_ uuid_ne - _null_ ));
+ DESCR("not-equal");
+ DATA(insert OID = 2960 (uuid_cmp PGNSP PGUID 12 1 0 f f t f i 2 23 "2950 2950" _null_ _null_ _null_ uuid_cmp - _null_ ));
+ DESCR("btree less-equal-greater");
+ DATA(insert OID = 2961 (uuid_recv PGNSP PGUID 12 1 0 f f t f i 1 2950 "2281" _null_ _null_ _null_ uuid_recv - _null_ ));
+ DESCR("I/O");
+ DATA(insert OID = 2962 (uuid_send PGNSP PGUID 12 1 0 f f t f i 1 17 "2950" _null_ _null_ _null_ uuid_send - _null_ ));
+ DESCR("I/O");
+ DATA(insert OID = 2963 (uuid_hash PGNSP PGUID 12 1 0 f f t f i 1 23 "2950" _null_ _null_ _null_ uuid_hash - _null_ ));
+ DESCR("hash");
+ DATA(insert OID = 2964 (uuid PGNSP PGUID 12 1 0 f f t f i 1 2950 "25" _null_ _null_ _null_ text_uuid - _null_ ));
+ DESCR("convert text to uuid");
+ DATA(insert OID = 2965 (text PGNSP PGUID 12 1 0 f f t f i 1 25 "2950" _null_ _null_ _null_ uuid_text - _null_ ));
+ DESCR("convert uuid to text");
+ DATA(insert OID = 2966 (uuid PGNSP PGUID 12 1 0 f f t f i 1 2950 "1043" _null_ _null_ _null_ varchar_uuid - _null_ ));
+ DESCR("convert varchar to uuid");
+ DATA(insert OID = 2967 (varchar PGNSP PGUID 12 1 0 f f t f i 1 1043 "2950" _null_ _null_ _null_ uuid_varchar - _null_ ));
+ DESCR("convert uuid to varchar");
+
/*
* Symbolic values for provolatile column: these indicate whether the result
***************
*** 4095,4097 ****
--- 4131,4134 ----
extern bool function_parse_error_transpose(const char *prosrc);
#endif /* PG_PROC_H */
+
*** ./src/include/catalog/pg_type.h.orig 2007-01-24 16:35:03.000000000 +0100
--- ./src/include/catalog/pg_type.h 2007-01-25 20:58:01.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+
+
/*-------------------------------------------------------------------------
*
* pg_type.h
***************
*** 561,566 ****
--- 563,573 ----
DATA(insert OID = 2283 ( anyelement PGNSP PGUID 4 t p t \054 0 0 anyelement_in anyelement_out - - - - - i p f 0 -1 0 _null_ _null_ ));
#define ANYELEMENTOID 2283
+ /* uuid */
+ DATA(insert OID = 2950 (uuid PGNSP PGUID 16 f b t \054 0 0 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 _null_ _null_ ));
+ DESCR("UUID/GUID datatype");
+ DATA(insert OID = 2951 (_uuid PGNSP PGUID -1 f b t \054 0 2950 array_in array_out array_recv array_send - - - i x f 0 -1 0 _null_ _null_ ));
+
/*
* prototypes for functions in pg_type.c
*/
***************
*** 614,616 ****
--- 621,624 ----
extern char *makeArrayTypeName(const char *typeName);
#endif /* PG_TYPE_H */
+
*** ./src/include/utils/builtins.h.orig 2007-01-24 16:35:03.000000000 +0100
--- ./src/include/utils/builtins.h 2007-01-24 16:43:26.000000000 +0100
***************
*** 926,929 ****
--- 926,947 ----
/* utils/mmgr/portalmem.c */
extern Datum pg_cursor(PG_FUNCTION_ARGS);
+ /* uuid.c */
+ extern Datum uuid_in(PG_FUNCTION_ARGS);
+ extern Datum uuid_out(PG_FUNCTION_ARGS);
+ extern Datum uuid_send(PG_FUNCTION_ARGS);
+ extern Datum uuid_recv(PG_FUNCTION_ARGS);
+ extern Datum uuid_lt(PG_FUNCTION_ARGS);
+ extern Datum uuid_le(PG_FUNCTION_ARGS);
+ extern Datum uuid_eq(PG_FUNCTION_ARGS);
+ extern Datum uuid_ge(PG_FUNCTION_ARGS);
+ extern Datum uuid_gt(PG_FUNCTION_ARGS);
+ extern Datum uuid_ne(PG_FUNCTION_ARGS);
+ extern Datum uuid_cmp(PG_FUNCTION_ARGS);
+ extern Datum uuid_hash(PG_FUNCTION_ARGS);
+ extern Datum text_uuid(PG_FUNCTION_ARGS);
+ extern Datum uuid_text(PG_FUNCTION_ARGS);
+ extern Datum varchar_uuid(PG_FUNCTION_ARGS);
+ extern Datum uuid_varchar(PG_FUNCTION_ARGS);
+
#endif /* BUILTINS_H */
*** ./src/include/utils/uuid.h.orig 1970-01-01 01:00:00.000000000 +0100
--- ./src/include/utils/uuid.h 2007-01-24 17:54:51.000000000 +0100
***************
*** 0 ****
--- 1,39 ----
+ /*-------------------------------------------------------------------------
+ *
+ * uuid.h
+ * Header file for the SQL datatypes UUID.
+ *
+ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
+ *
+ *-------------------------------------------------------------------------
+ */
+ #ifndef UUID_H
+ #define UUID_H
+
+ /* Accepted GUID formats */
+
+ #define UUID_FMT1 "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+ #define UUID_FMT2 "{%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx}"
+ // also the default output type
+ #define UUID_FMT3 "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
+
+ /* The guid size */
+ #define UUID_LEN 16
+ /* output length */
+ #define PRINT_SIZE 40
+
+ /* uuid type structure */
+ typedef struct uuid_t {
+ char data[UUID_LEN];
+ } uuid_t;
+
+
+
+ /* fmgr interface macros */
+ #define UUIDPGetDatum(X) PointerGetDatum(X)
+ #define PG_RETURN_UUID_P(X) return UUIDPGetDatum(X)
+
+ #define DatumGetUUIDP(X) ((uuid_t *) DatumGetPointer(X))
+ #define PG_GETARG_UUID_P(X) DatumGetUUIDP(PG_GETARG_DATUM(X))
+
+ #endif /* UUID_H */
*** ./src/test/regress/expected/uuid.out.orig 1970-01-01 01:00:00.000000000 +0100
--- ./src/test/regress/expected/uuid.out 2007-01-25 21:09:29.000000000 +0100
***************
*** 0 ****
--- 1,122 ----
+ --regression test for the uuid datatype
+
+ -- creating test tables
+ create table guid1
+ (
+ guid_field uuid,
+ text_field text default(now())
+ );
+
+ create table guid2
+ (
+ guid_field uuid,
+ text_field text default(now())
+ );
+
+ -- test 1: inserting by three input formats
+ insert into guid1(guid_field) values('11111111-1111-1111-1111-111111111111');
+ insert into guid1(guid_field) values('{22222222-2222-2222-2222-222222222222}');
+ insert into guid1(guid_field) values('33333333333333333333333333333333');
+ -- test 2: retriving the inserted datat
+ select guid_field from guid1;
+ guid_field
+ --------------------------------------
+ 11111111-1111-1111-1111-111111111111
+ 22222222-2222-2222-2222-222222222222
+ 33333333-3333-3333-3333-333333333333
+ (3 rows)
+
+
+ -- test 3: ordering test
+ select guid_field from guid1 order by guid_field asc;
+ guid_field
+ --------------------------------------
+ 11111111-1111-1111-1111-111111111111
+ 22222222-2222-2222-2222-222222222222
+ 33333333-3333-3333-3333-333333333333
+ (3 rows)
+
+ select guid_field from guid1 order by guid_field desc;
+ guid_field
+ --------------------------------------
+ 33333333-3333-3333-3333-333333333333
+ 22222222-2222-2222-2222-222222222222
+ 11111111-1111-1111-1111-111111111111
+ (3 rows)
+
+
+ -- test 4: = opertator test
+ select count(*) from guid1 where guid_field = '33333333-3333-3333-3333-333333333333';
+ count
+ -------
+ 1
+ (1 row)
+
+
+ -- test 5: <> opertator test
+ select count(*) from guid1 where guid_field <> '11111111111111111111111111111111';
+ count
+ -------
+ 2
+ (1 row)
+
+
+ -- test 6: < operator test
+ select count(*) from guid1 where guid_field < '22222222-2222-2222-2222-222222222222';
+ count
+ -------
+ 1
+ (1 row)
+
+
+ -- test 7: <= operator test
+ select count(*) from guid1 where guid_field <= '22222222-2222-2222-2222-222222222222';
+ count
+ -------
+ 2
+ (1 row)
+
+
+ -- test 8: > operator test
+ select count(*) from guid1 where guid_field > '22222222-2222-2222-2222-222222222222';
+ count
+ -------
+ 1
+ (1 row)
+
+ -- test 9 => operator test
+ select count(*) from guid1 where guid_field >= '22222222-2222-2222-2222-222222222222';
+ count
+ -------
+ 2
+ (1 row)
+
+
+
+ -- btree and hash index creation test
+ create index guid1_btree on guid1 using btree (guid_field);
+ create index guid1_hash on guid1 using hash (guid_field);
+
+ -- unique index test
+ create unique index guid1_unique_btree on guid1 using btree (guid_field);
+
+ -- populating the test tables with additional records
+ insert into guid1(guid_field) values('44444444-4444-4444-4444-444444444444');
+ insert into guid2(guid_field) values('11111111-1111-1111-1111-111111111111');
+ insert into guid2(guid_field) values('{22222222-2222-2222-2222-222222222222}');
+ insert into guid2(guid_field) values('33333333333333333333333333333333');
+ -- join test
+ select count(*) from guid1 g1 inner join guid2 g2 on g1.guid_field = g2.guid_field;
+ count
+ -------
+ 3
+ (1 row)
+
+ select count(*) from guid1 g1 left join guid2 g2 on g1.guid_field = g2.guid_field where g2.guid_field is null;
+ count
+ -------
+ 1
+ (1 row)
+
+ -- clean up
+ drop table guid1,guid2 cascade;
*** ./src/test/regress/parallel_schedule.orig 2007-01-24 16:35:06.000000000 +0100
--- ./src/test/regress/parallel_schedule 2007-01-24 16:51:34.000000000 +0100
***************
*** 2,8 ****
# The first group of parallel test
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.37 2007/01/20 17:15:43 neilc Exp $
# ----------
! test: boolean char name varchar text int2 int4 int8 oid float4 float8 bit numeric
# Depends on things setup during char, varchar and text
test: strings
--- 2,8 ----
# The first group of parallel test
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.37 2007/01/20 17:15:43 neilc Exp $
# ----------
! test: uuid boolean char name varchar text int2 int4 int8 oid float4 float8 bit numeric
# Depends on things setup during char, varchar and text
test: strings
*** ./src/test/regress/serial_schedule.orig 2007-01-24 16:35:06.000000000 +0100
--- ./src/test/regress/serial_schedule 2007-01-24 16:52:06.000000000 +0100
***************
*** 1,5 ****
--- 1,6 ----
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.35 2007/01/20 17:15:43 neilc Exp $
# This should probably be in an order similar to parallel_schedule.
+ test: uuid
test: boolean
test: char
test: name
*** ./src/test/regress/sql/uuid.sql.orig 1970-01-01 01:00:00.000000000 +0100
--- ./src/test/regress/sql/uuid.sql 2006-09-19 13:34:51.000000000 +0200
***************
*** 0 ****
--- 1,67 ----
+ --regression test for the uuid datatype
+
+ -- creating test tables
+ create table guid1
+ (
+ guid_field uuid,
+ text_field text default(now())
+ );
+
+ create table guid2
+ (
+ guid_field uuid,
+ text_field text default(now())
+ );
+
+ -- test 1: inserting by three input formats
+ insert into guid1(guid_field) values('11111111-1111-1111-1111-111111111111');
+ insert into guid1(guid_field) values('{22222222-2222-2222-2222-222222222222}');
+ insert into guid1(guid_field) values('33333333333333333333333333333333');
+
+ -- test 2: retriving the inserted datat
+ select guid_field from guid1;
+
+ -- test 3: ordering test
+ select guid_field from guid1 order by guid_field asc;
+ select guid_field from guid1 order by guid_field desc;
+
+ -- test 4: = opertator test
+ select count(*) from guid1 where guid_field = '33333333-3333-3333-3333-333333333333';
+
+ -- test 5: <> opertator test
+ select count(*) from guid1 where guid_field <> '11111111111111111111111111111111';
+
+ -- test 6: < operator test
+ select count(*) from guid1 where guid_field < '22222222-2222-2222-2222-222222222222';
+
+ -- test 7: <= operator test
+ select count(*) from guid1 where guid_field <= '22222222-2222-2222-2222-222222222222';
+
+ -- test 8: > operator test
+ select count(*) from guid1 where guid_field > '22222222-2222-2222-2222-222222222222';
+
+ -- test 9 => operator test
+ select count(*) from guid1 where guid_field >= '22222222-2222-2222-2222-222222222222';
+
+
+ -- btree and hash index creation test
+ create index guid1_btree on guid1 using btree (guid_field);
+ create index guid1_hash on guid1 using hash (guid_field);
+
+ -- unique index test
+ create unique index guid1_unique_btree on guid1 using btree (guid_field);
+
+
+ -- populating the test tables with additional records
+ insert into guid1(guid_field) values('44444444-4444-4444-4444-444444444444');
+
+ insert into guid2(guid_field) values('11111111-1111-1111-1111-111111111111');
+ insert into guid2(guid_field) values('{22222222-2222-2222-2222-222222222222}');
+ insert into guid2(guid_field) values('33333333333333333333333333333333');
+
+ -- join test
+ select count(*) from guid1 g1 inner join guid2 g2 on g1.guid_field = g2.guid_field;
+ select count(*) from guid1 g1 left join guid2 g2 on g1.guid_field = g2.guid_field where g2.guid_field is null;
+
+ -- clean up
+ drop table guid1,guid2 cascade;
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster