pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14670: uuid_generate_v3 and uuid_generate_v5 do not support binary names
5+ messages / 4 participants
[nested] [flat]

* BUG #14670: uuid_generate_v3 and uuid_generate_v5 do not support binary names
@ 2017-05-24 20:46  mohd.akram@live.com
  0 siblings, 1 reply; 5+ messages in thread

From: mohd.akram@live.com @ 2017-05-24 20:46 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14670
Logged by:          Mohamed Akram
Email address:      mohd.akram@live.com
PostgreSQL version: 9.6.3
Operating system:   macOS 10.12.5
Description:        

As per RFC 4122 - https://tools.ietf.org/html/rfc4122#section-4.3 - name
should not be limited to textual data.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #14670: uuid_generate_v3 and uuid_generate_v5 do not support binary names
@ 2017-05-24 21:26  David G. Johnston <david.g.johnston@gmail.com>
  parent: mohd.akram@live.com
  0 siblings, 1 reply; 5+ messages in thread

From: David G. Johnston @ 2017-05-24 21:26 UTC (permalink / raw)
  To: mohd.akram@live.com; +Cc: pgsql-bugs

On Wed, May 24, 2017 at 1:46 PM, <mohd.akram@live.com> wrote:

> The following bug has been logged on the website:
>
> Bug reference:      14670
> Logged by:          Mohamed Akram
> Email address:      mohd.akram@live.com
> PostgreSQL version: 9.6.3
> Operating system:   macOS 10.12.5
> Description:
>
> As per RFC 4122 - https://tools.ietf.org/html/rfc4122#section-4.3 - name
> should not be limited to textual data.
>

​Since it says should and not must an implementation that restricts the
name to be textual is still conforming.

Apart from that supplying an SQL example of what you want to work and what
happens when it fails would reduce the possibility of mis-understanding
what it is you are saying.​

David J.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #14670: uuid_generate_v3 and uuid_generate_v5 do not support binary names
@ 2017-05-24 21:54  Mohamed Akram <mohd.akram@outlook.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Mohamed Akram @ 2017-05-24 21:54 UTC (permalink / raw)
  To: pgsql-bugs

That’s true, I guess it’s more of an enhancement but I couldn’t find an option for that in the bug form. However, even the sample C code in the RFC takes a void* argument for name.

My use case is generating unique identifiers for images, similar to:

select uuid_generate_v5(namespace, data);

where data is a bytea column.

I know I can convert to base64, but I’d rather not.

On May 25, 2017, at 1:26 AM, David G. Johnston <david.g.johnston@gmail.com<mailto:david.g.johnston@gmail.com>> wrote:

On Wed, May 24, 2017 at 1:46 PM, <mohd.akram@live.com<mailto:mohd.akram@live.com>> wrote:
The following bug has been logged on the website:

Bug reference:      14670
Logged by:          Mohamed Akram
Email address:      mohd.akram@live.com<mailto:mohd.akram@live.com>
PostgreSQL version: 9.6.3
Operating system:   macOS 10.12.5
Description:

As per RFC 4122 - https://tools.ietf.org/html/rfc4122#section-4.3 - name
should not be limited to textual data.

​Since it says should and not must an implementation that restricts the name to be textual is still conforming.

Apart from that supplying an SQL example of what you want to work and what happens when it fails would reduce the possibility of mis-understanding what it is you are saying.​

David J.




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #14670: uuid_generate_v3 and uuid_generate_v5 do not support binary names
@ 2017-05-24 22:48  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Mohamed Akram <mohd.akram@outlook.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2017-05-24 22:48 UTC (permalink / raw)
  To: Mohamed Akram <mohd.akram@outlook.com>; +Cc: pgsql-bugs

Mohamed Akram <mohd.akram@outlook.com> writes:
> That’s true, I guess it’s more of an enhancement but I couldn’t find an option for that in the bug form. However, even the sample C code in the RFC takes a void* argument for name.
> My use case is generating unique identifiers for images, similar to:
> select uuid_generate_v5(namespace, data);
> where data is a bytea column.

A little experimentation suggests that we might be able to add a function
uuid_generate_v3(uuid, bytea) alongside the uuid_generate_v3(uuid, text)
one without creating serious problems --- in ambiguous situations, it
seems the text one would be preferred, so we'd not break existing queries.

I have no interest in preparing such a patch myself, though.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #14670: uuid_generate_v3 and uuid_generate_v5 do not support binary names
@ 2017-06-20 13:57  Mohamed Akram <mohd.akram@outlook.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Mohamed Akram @ 2017-06-20 13:57 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

I’ve attached a patch for this.

Regards,
Mohamed


> On May 25, 2017, at 2:48 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Mohamed Akram <mohd.akram@outlook.com> writes:
>> That’s true, I guess it’s more of an enhancement but I couldn’t find an option for that in the bug form. However, even the sample C code in the RFC takes a void* argument for name.
>> My use case is generating unique identifiers for images, similar to:
>> select uuid_generate_v5(namespace, data);
>> where data is a bytea column.
>
> A little experimentation suggests that we might be able to add a function
> uuid_generate_v3(uuid, bytea) alongside the uuid_generate_v3(uuid, text)
> one without creating serious problems --- in ambiguous situations, it
> seems the text one would be preferred, so we'd not break existing queries.
>
> I have no interest in preparing such a patch myself, though.
>
>                        regards, tom lane



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

uuid-bytea.diff (application/octet-stream, 7.5K) download diff --git a/contrib/uuid-ossp/Makefile b/contrib/uuid-ossp/Makefile index c52c583d648..48d2523d4a4 100644 --- a/contrib/uuid-ossp/Makefile +++ b/contrib/uuid-ossp/Makefile @@ -4,7 +4,8 @@ MODULE_big = uuid-ossp OBJS = uuid-ossp.o $(UUID_EXTRA_OBJS) $(WIN32RES) EXTENSION = uuid-ossp -DATA = uuid-ossp--1.1.sql uuid-ossp--1.0--1.1.sql uuid-ossp--unpackaged--1.0.sql +DATA = uuid-ossp--1.2.sql uuid-ossp--1.1--1.2.sql uuid-ossp--1.0--1.1.sql \ + uuid-ossp--unpackaged--1.0.sql PGFILEDESC = "uuid-ossp - UUID generation" REGRESS = uuid_ossp diff --git a/contrib/uuid-ossp/expected/uuid_ossp.out b/contrib/uuid-ossp/expected/uuid_ossp.out index 409c885c33a..1c54c6ef129 100644 --- a/contrib/uuid-ossp/expected/uuid_ossp.out +++ b/contrib/uuid-ossp/expected/uuid_ossp.out @@ -118,12 +118,24 @@ SELECT uuid_generate_v3(uuid_ns_dns(), 'www.widgets.com'); 3d813cbb-47fb-32ba-91df-831e1593ac29 (1 row) +SELECT uuid_generate_v3(uuid_nil(), '\x00ABCDEF'::bytea); + uuid_generate_v3 +-------------------------------------- + ab97c525-de95-3d08-a34a-bdb16bda93ca +(1 row) + SELECT uuid_generate_v5(uuid_ns_dns(), 'www.widgets.com'); uuid_generate_v5 -------------------------------------- 21f7f8de-8051-5b89-8680-0195ef798b6a (1 row) +SELECT uuid_generate_v5(uuid_nil(), '\x00ABCDEF'::bytea); + uuid_generate_v5 +-------------------------------------- + c52b4615-61e8-522c-a42e-8feb48af3958 +(1 row) + SELECT uuid_version_bits(uuid_generate_v4()), uuid_reserved_bits(uuid_generate_v4()); uuid_version_bits | uuid_reserved_bits diff --git a/contrib/uuid-ossp/sql/uuid_ossp.sql b/contrib/uuid-ossp/sql/uuid_ossp.sql index b4237df8847..f5f06d62260 100644 --- a/contrib/uuid-ossp/sql/uuid_ossp.sql +++ b/contrib/uuid-ossp/sql/uuid_ossp.sql @@ -67,7 +67,10 @@ SELECT uuid_node(uuid_generate_v1()) <> uuid_node(uuid_generate_v1mc()); SELECT uuid_node(uuid_generate_v1mc()) <> uuid_node(uuid_generate_v1mc()); SELECT uuid_generate_v3(uuid_ns_dns(), 'www.widgets.com'); +SELECT uuid_generate_v3(uuid_nil(), '\x00ABCDEF'::bytea); + SELECT uuid_generate_v5(uuid_ns_dns(), 'www.widgets.com'); +SELECT uuid_generate_v5(uuid_nil(), '\x00ABCDEF'::bytea); SELECT uuid_version_bits(uuid_generate_v4()), uuid_reserved_bits(uuid_generate_v4()); diff --git a/contrib/uuid-ossp/uuid-ossp--1.1--1.2.sql b/contrib/uuid-ossp/uuid-ossp--1.1--1.2.sql new file mode 100644 index 00000000000..687d628aa30 --- /dev/null +++ b/contrib/uuid-ossp/uuid-ossp--1.1--1.2.sql @@ -0,0 +1,14 @@ +/* contrib/uuid-ossp/uuid-ossp--1.1--1.2.sql */ + +-- complain if script is sourced in psql, rather than via ALTER EXTENSION +\echo Use "ALTER EXTENSION uuid-ossp UPDATE TO '1.2'" to load this file. \quit + +CREATE FUNCTION uuid_generate_v3(namespace uuid, name bytea) +RETURNS uuid +AS 'MODULE_PATHNAME', 'uuid_generate_v3_bytea' +IMMUTABLE STRICT LANGUAGE C PARALLEL SAFE; + +CREATE FUNCTION uuid_generate_v5(namespace uuid, name bytea) +RETURNS uuid +AS 'MODULE_PATHNAME', 'uuid_generate_v5_bytea' +IMMUTABLE STRICT LANGUAGE C PARALLEL SAFE; diff --git a/contrib/uuid-ossp/uuid-ossp--1.1.sql b/contrib/uuid-ossp/uuid-ossp--1.2.sql similarity index 82% rename from contrib/uuid-ossp/uuid-ossp--1.1.sql rename to contrib/uuid-ossp/uuid-ossp--1.2.sql index c9cefd73608..a9c211447db 100644 --- a/contrib/uuid-ossp/uuid-ossp--1.1.sql +++ b/contrib/uuid-ossp/uuid-ossp--1.2.sql @@ -43,6 +43,11 @@ RETURNS uuid AS 'MODULE_PATHNAME', 'uuid_generate_v3' IMMUTABLE STRICT LANGUAGE C PARALLEL SAFE; +CREATE FUNCTION uuid_generate_v3(namespace uuid, name bytea) +RETURNS uuid +AS 'MODULE_PATHNAME', 'uuid_generate_v3_bytea' +IMMUTABLE STRICT LANGUAGE C PARALLEL SAFE; + CREATE FUNCTION uuid_generate_v4() RETURNS uuid AS 'MODULE_PATHNAME', 'uuid_generate_v4' @@ -52,3 +57,8 @@ CREATE FUNCTION uuid_generate_v5(namespace uuid, name text) RETURNS uuid AS 'MODULE_PATHNAME', 'uuid_generate_v5' IMMUTABLE STRICT LANGUAGE C PARALLEL SAFE; + +CREATE FUNCTION uuid_generate_v5(namespace uuid, name bytea) +RETURNS uuid +AS 'MODULE_PATHNAME', 'uuid_generate_v5_bytea' +IMMUTABLE STRICT LANGUAGE C PARALLEL SAFE; diff --git a/contrib/uuid-ossp/uuid-ossp.c b/contrib/uuid-ossp/uuid-ossp.c index 1ce08555cfb..8e9f5e825d1 100644 --- a/contrib/uuid-ossp/uuid-ossp.c +++ b/contrib/uuid-ossp/uuid-ossp.c @@ -123,8 +123,10 @@ PG_FUNCTION_INFO_V1(uuid_ns_x500); PG_FUNCTION_INFO_V1(uuid_generate_v1); PG_FUNCTION_INFO_V1(uuid_generate_v1mc); PG_FUNCTION_INFO_V1(uuid_generate_v3); +PG_FUNCTION_INFO_V1(uuid_generate_v3_bytea); PG_FUNCTION_INFO_V1(uuid_generate_v4); PG_FUNCTION_INFO_V1(uuid_generate_v5); +PG_FUNCTION_INFO_V1(uuid_generate_v5_bytea); #ifdef HAVE_UUID_OSSP @@ -515,6 +517,21 @@ uuid_generate_v3(PG_FUNCTION_ARGS) Datum +uuid_generate_v3_bytea(PG_FUNCTION_ARGS) +{ + pg_uuid_t *ns = PG_GETARG_UUID_P(0); + bytea *name = PG_GETARG_BYTEA_PP(1); + +#ifdef HAVE_UUID_OSSP + return uuid_generate_v35_internal(UUID_MAKE_V3, ns, name); +#else + return uuid_generate_internal(UUID_MAKE_V3, (unsigned char *) ns, + VARDATA_ANY(name), VARSIZE_ANY_EXHDR(name)); +#endif +} + + +Datum uuid_generate_v4(PG_FUNCTION_ARGS) { return uuid_generate_internal(UUID_MAKE_V4, NULL, NULL, 0); @@ -534,3 +551,18 @@ uuid_generate_v5(PG_FUNCTION_ARGS) VARDATA_ANY(name), VARSIZE_ANY_EXHDR(name)); #endif } + + +Datum +uuid_generate_v5_bytea(PG_FUNCTION_ARGS) +{ + pg_uuid_t *ns = PG_GETARG_UUID_P(0); + bytea *name = PG_GETARG_BYTEA_PP(1); + +#ifdef HAVE_UUID_OSSP + return uuid_generate_v35_internal(UUID_MAKE_V5, ns, name); +#else + return uuid_generate_internal(UUID_MAKE_V5, (unsigned char *) ns, + VARDATA_ANY(name), VARSIZE_ANY_EXHDR(name)); +#endif +} diff --git a/contrib/uuid-ossp/uuid-ossp.control b/contrib/uuid-ossp/uuid-ossp.control index 657476c182f..3479b06eff7 100644 --- a/contrib/uuid-ossp/uuid-ossp.control +++ b/contrib/uuid-ossp/uuid-ossp.control @@ -1,5 +1,5 @@ # uuid-ossp extension comment = 'generate universally unique identifiers (UUIDs)' -default_version = '1.1' +default_version = '1.2' module_pathname = '$libdir/uuid-ossp' relocatable = true diff --git a/doc/src/sgml/uuid-ossp.sgml b/doc/src/sgml/uuid-ossp.sgml index 227d4a839c8..235e22578e1 100644 --- a/doc/src/sgml/uuid-ossp.sgml +++ b/doc/src/sgml/uuid-ossp.sgml @@ -58,7 +58,11 @@ </entry> </row> <row> - <entry><function>uuid_generate_v3(namespace uuid, name text)</function><indexterm><primary>uuid_generate_v3</primary></indexterm></entry> + <entry> + <function>uuid_generate_v3(namespace uuid, name text)</function> + <function>uuid_generate_v3(namespace uuid, name bytea)</function> + <indexterm><primary>uuid_generate_v3</primary></indexterm> + </entry> <entry> <para> This function generates a version 3 UUID in the given namespace using @@ -92,7 +96,11 @@ SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org'); </entry> </row> <row> - <entry><literal>uuid_generate_v5(namespace uuid, name text)</literal></entry> + <entry> + <function>uuid_generate_v5(namespace uuid, name text)</function> + <function>uuid_generate_v5(namespace uuid, name bytea)</function> + <indexterm><primary>uuid_generate_v5</primary></indexterm> + </entry> <entry> <para> This function generates a version 5 UUID, which works like a version 3
^ permalink raw reply [nested|flat] 5+ messages in thread


end of thread, other threads:[~2017-06-20 13:57 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-05-24 20:46 BUG #14670: uuid_generate_v3 and uuid_generate_v5 do not support binary names mohd.akram@live.com
2017-05-24 21:26 ` David G. Johnston <david.g.johnston@gmail.com>
2017-05-24 21:54   ` Mohamed Akram <mohd.akram@outlook.com>
2017-05-24 22:48     ` Tom Lane <tgl@sss.pgh.pa.us>
2017-06-20 13:57       ` Mohamed Akram <mohd.akram@outlook.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox