Issue 2: UUID type not useable as primary key
Status:  New
Owner: ----
Reported by Rra...@gmail.com, Sep 6, 2007
What steps will reproduce the problem?

1. CREATE TABLE t (id UUID DEFAULT UUID() PRIMARY KEY, data VARCHAR);

2. INSERT INTO t (data) VALUES ('foo');
INSERT INTO t (data) VALUES ('bar');


What is the expected output? What do you see instead?

# SELECT * FROM t;
                  id                  | data 
--------------------------------------+------
 52336ccf-330e-4045-a4c7-ec12e7defdaf | foo
 196d3306-8c6b-4b93-a02d-bdd0ef9ad0ac | bar
(2 rows) # <== OK

# SELECT * FROM t WHERE id = '196d3306-8c6b-4b93-a02d-bdd0ef9ad0ac';
                  id                  | data 
--------------------------------------+------
 196d3306-8c6b-4b93-a02d-bdd0ef9ad0ac | bar
(1 row) # <== OK

# SELECT * FROM t WHERE id = '52336ccf-330e-4045-a4c7-ec12e7defdaf';
 id | data 
----+------
(0 rows) <== Wrong. Should select 1 row instead of 0 rows.


What version of the product are you using? On what operating system?
PostgresQL 8.2.4, 32-bits linux; Revision 10 of polarrose-postgresql-uuid.


Please provide any additional information below.
When inserting more rows, only the last inserted row can be selected on the
uuid. All other uuids cannot be selected.
Sep 6, 2007
#1 Rra...@gmail.com
Gotcha. Bug in uuid.c, line 125:

$ diff -ruN uuid.c.original uuid.c
--- uuid.c.original     2007-09-06 21:37:42.000000000 +0200
+++ uuid.c      2007-09-06 21:39:25.000000000 +0200
@@ -122,7 +122,7 @@
 {
    polarrose_uuid_t* a = (polarrose_uuid_t*) PG_GETARG_POINTER(0);
    polarrose_uuid_t* b = (polarrose_uuid_t*) PG_GETARG_POINTER(1);
-   PG_RETURN_BOOL(polarrose_uuid_cmp_internal(a, b) != 0);
+   PG_RETURN_INT32(polarrose_uuid_cmp_internal(a, b));
 }
 
 PG_FUNCTION_INFO_V1(polarrose_uuid_to_text);


Apply patch, recompile, reinstall, rerun uuid.sql.

Regards,
R.

Feb 6, 2010
#2 gim...@gmail.com
Looks like this is a closed issue?