<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jontas &#187; uuid</title>
	<atom:link href="http://www.f15ijp.com/tag/uuid/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.f15ijp.com</link>
	<description>My digital notepad (notes etc)</description>
	<lastBuildDate>Wed, 28 Dec 2011 18:24:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PostgreSQL 8.3 adding uuid-ossp on Debian</title>
		<link>http://www.f15ijp.com/2010/10/03/postgresql-8-3-adding-uuid-ossp-on-debian/</link>
		<comments>http://www.f15ijp.com/2010/10/03/postgresql-8-3-adding-uuid-ossp-on-debian/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 09:53:23 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[Postgres]]></category>
		<category><![CDATA[PostgreSQL module]]></category>
		<category><![CDATA[uuid]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=675</guid>
		<description><![CDATA[UUID is a nice way to generate (almost) unique id&#8217;s. However on PostgreSQL 8.3 the data type exists, but if you wish to be able to generate UUID&#8217;s you need to get a module (in this case uuid-ossp). On Debian this module is in the contrib package, so if you have not installed this before [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/UUID">UUID</a> is a nice way to generate (almost) unique id&#8217;s.</p>
<p>However on PostgreSQL 8.3 the data type exists, but if you wish to be able to generate UUID&#8217;s you need to get a module (in this case <a href="http://www.postgresql.org/docs/8.3/static/uuid-ossp.html">uuid-ossp</a>).</p>
<p>On Debian this module is in the contrib package, so if you have not installed this before do it now</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>server:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> postgresql-contrib</pre></div></div>

<p>Then you need to &#8220;load&#8221; the module into PostgreSQL; or more accurately you tell PostgreSQL about the new functions this module has, how to reach them etc.<br />
Depending on you security settings (in pg_hba.conf) you may need to log in as the postgres user on your system.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">postgres<span style="color: #000000; font-weight: bold;">@</span>sever:~$ psql <span style="color: #660033;">-d</span> MYDB <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>postgresql<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8.3</span><span style="color: #000000; font-weight: bold;">/</span>contrib<span style="color: #000000; font-weight: bold;">/</span>uuid-ossp.sql</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/10/03/postgresql-8-3-adding-uuid-ossp-on-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MYSQL Creating several UUIDs at one single time</title>
		<link>http://www.f15ijp.com/2010/07/14/mysql-creating-several-uuids-at-one-single-time/</link>
		<comments>http://www.f15ijp.com/2010/07/14/mysql-creating-several-uuids-at-one-single-time/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 06:56:07 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[uuid]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=543</guid>
		<description><![CDATA[I recently ran into the problem that I had too add two rows to a database that uses a UUID (in this case converted to a binary) as a key. The problem I had was that running two insert statements after each other (just separated by &#8220;;&#8221;) then the same id was generated. A workaround [...]]]></description>
			<content:encoded><![CDATA[<p>I recently ran into the problem that I had too add two rows to a database that uses a UUID (in this case converted to a binary) as a key.<br />
The problem I had was that running two insert statements after each other (just separated by &#8220;;&#8221;) then the same id was generated.<br />
A workaround I have found is to sleep for a second between the two statements.</p>
<p>Examples (using SELECT instead of INSERT):<br />
Getting the same id twice</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> UNHEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>UUID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> uuid1<span style="color: #66cc66;">,</span>  UNHEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>UUID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> uuid2;
<span style="color: #808080; font-style: italic;">-- Shows: &quot;849392548f1311df91b70019dbd264f1&quot;	&quot;849392908f1311df91b70019dbd264f1&quot;</span></pre></div></div>

<p>Adding a sleep to get different ids</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> UNHEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>UUID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> uuid1<span style="color: #66cc66;">,</span> SLEEP<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> UNHEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>UUID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> uuid2
<span style="color: #808080; font-style: italic;">-- Shows: &quot;3901c1928f1511df91b70019dbd264f1&quot;	&quot;0&quot;	&quot;399a5b148f1511df91b70019dbd264f1&quot;</span></pre></div></div>

<p>And another one using INSERTS</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> testTable <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>UNHEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>UUID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
SLEEP<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> testTable <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>UNHEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>UUID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/07/14/mysql-creating-several-uuids-at-one-single-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: converting a uuid stored as BINARY(16) in mysql to RFC 4122 format</title>
		<link>http://www.f15ijp.com/2010/06/16/php-converting-a-uuid-stored-as-binary16-in-mysql-to-rfc-4122-format/</link>
		<comments>http://www.f15ijp.com/2010/06/16/php-converting-a-uuid-stored-as-binary16-in-mysql-to-rfc-4122-format/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 13:16:19 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[PHP5]]></category>
		<category><![CDATA[uuid]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=505</guid>
		<description><![CDATA[If you are storing uuid&#8217;s are BINARY(16) in the database, then the following will turn the stored id to the &#8220;original&#8221; format. $uuidReadable = unpack&#40;&#34;h*&#34;,$uuid&#41;; $uuidReadable = preg_replace&#40;&#34;/([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})/&#34;, &#34;$1-$2-$3-$4-$5&#34;, $uuidReadable&#41;; $uuidReadable = array_merge&#40;$uuidReadable&#41;; echo &#34;uuid is &#34; . $uuidReadable&#91;0&#93;;]]></description>
			<content:encoded><![CDATA[<p>If you are <a href="http://www.f15ijp.com/2010/06/16/mysql-inserting-uuid-to-a-binary16-field/">storing uuid&#8217;s are BINARY(16) in the database</a>, then the following will turn the stored id to the &#8220;original&#8221; format.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$uuidReadable</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unpack</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;h*&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$uuid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$uuidReadable</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$1</span>-<span style="color: #006699; font-weight: bold;">$2</span>-<span style="color: #006699; font-weight: bold;">$3</span>-<span style="color: #006699; font-weight: bold;">$4</span>-<span style="color: #006699; font-weight: bold;">$5</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$uuidReadable</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$uuidReadable</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uuidReadable</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;uuid is &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$uuidReadable</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/06/16/php-converting-a-uuid-stored-as-binary16-in-mysql-to-rfc-4122-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL inserting UUID to a binary(16) field</title>
		<link>http://www.f15ijp.com/2010/06/16/mysql-inserting-uuid-to-a-binary16-field/</link>
		<comments>http://www.f15ijp.com/2010/06/16/mysql-inserting-uuid-to-a-binary16-field/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 13:11:45 +0000</pubDate>
		<dc:creator>jontas</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[uuid]]></category>

		<guid isPermaLink="false">http://www.f15ijp.com/?p=503</guid>
		<description><![CDATA[It is advantageous to store a UUID (acc to RFC 4122) in a binary(16) field in the database. It is not hard to create such a table and to insert data into it. CREATE TABLE IF NOT EXISTS test_table &#40; id BINARY&#40;16&#41; NOT NULL, name VARCHAR&#40;128&#41; NOT NULL, PRIMARY KEY &#40;id&#41; &#41; &#160; INSERT INTO [...]]]></description>
			<content:encoded><![CDATA[<p>It is advantageous to store a <a href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier">UUID</a> (acc to RFC 4122) in a binary(16) field in the database.<br />
It is not hard to create such a table and to insert data into it.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> test_table <span style="color: #66cc66;">&#40;</span>
  id <span style="color: #993333; font-weight: bold;">BINARY</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  name <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> 
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> test_table <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">,</span> name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span>
<span style="color: #66cc66;">&#40;</span>UNHEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>UUID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'test1'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#40;</span>UNHEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>UUID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'test2'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#40;</span>UNHEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>UUID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'test3'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.f15ijp.com/2010/06/16/mysql-inserting-uuid-to-a-binary16-field/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

