<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Converting from UUIDs to GUIDs</title>
	<atom:link href="http://www.ghidinelli.com/2008/12/16/converting-from-uuids-to-guids/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ghidinelli.com/2008/12/16/converting-from-uuids-to-guids</link>
	<description></description>
	<lastBuildDate>Thu, 26 Jan 2012 23:33:32 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Orange is my favorite color &#187; Blog Archive &#187; Converting from UUIDs to GUIDs - Solution</title>
		<link>http://www.ghidinelli.com/2008/12/16/converting-from-uuids-to-guids/comment-page-1#comment-53022</link>
		<dc:creator>Orange is my favorite color &#187; Blog Archive &#187; Converting from UUIDs to GUIDs - Solution</dc:creator>
		<pubDate>Sat, 20 Dec 2008 23:32:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.ghidinelli.com/?p=429#comment-53022</guid>
		<description>[...] my previous post, I detailed my desire to convert from char(35) to Postgres&#8217; native uuid datatype for storing [...]</description>
		<content:encoded><![CDATA[<p>[...] my previous post, I detailed my desire to convert from char(35) to Postgres&#8217; native uuid datatype for storing [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.ghidinelli.com/2008/12/16/converting-from-uuids-to-guids/comment-page-1#comment-52939</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Tue, 16 Dec 2008 23:27:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.ghidinelli.com/?p=429#comment-52939</guid>
		<description>@Jochem - strange - I went looking in CVS and 8.3.0 has that same comment but it doesn&#039;t work for me.  I am trying this on 8.3.4 on Windows... so not sure what&#039;s going on but I ran this:

&lt;pre&gt;&lt;code&gt;
BEGIN;

SET CONSTRAINTS ALL DEFERRED; 
ALTER TABLE uuidTest DISABLE TRIGGER ALL;
ALTER TABLE uuidTest_ref DISABLE TRIGGER ALL;

ALTER TABLE uuidtest ALTER COLUMN uidTest TYPE uuid USING uidTest::uuid;
ALTER TABLE uuidtest_ref ALTER COLUMN uidTest TYPE uuid USING uidTest::uuid;

ALTER TABLE uuidTest ENABLE TRIGGER ALL;
ALTER TABLE uuidTest_ref ENABLE TRIGGER ALL;

COMMIT;
&lt;/code&gt;&lt;/pre&gt;

No combination of the transaction, constraint or trigger syntax seems to fix this.</description>
		<content:encoded><![CDATA[<p>@Jochem &#8211; strange &#8211; I went looking in CVS and 8.3.0 has that same comment but it doesn&#8217;t work for me.  I am trying this on 8.3.4 on Windows&#8230; so not sure what&#8217;s going on but I ran this:</p>
<pre><code>
BEGIN;

SET CONSTRAINTS ALL DEFERRED;
ALTER TABLE uuidTest DISABLE TRIGGER ALL;
ALTER TABLE uuidTest_ref DISABLE TRIGGER ALL;

ALTER TABLE uuidtest ALTER COLUMN uidTest TYPE uuid USING uidTest::uuid;
ALTER TABLE uuidtest_ref ALTER COLUMN uidTest TYPE uuid USING uidTest::uuid;

ALTER TABLE uuidTest ENABLE TRIGGER ALL;
ALTER TABLE uuidTest_ref ENABLE TRIGGER ALL;

COMMIT;
</code></pre>
<p>No combination of the transaction, constraint or trigger syntax seems to fix this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jochem van Dieten</title>
		<link>http://www.ghidinelli.com/2008/12/16/converting-from-uuids-to-guids/comment-page-1#comment-52937</link>
		<dc:creator>Jochem van Dieten</dc:creator>
		<pubDate>Tue, 16 Dec 2008 21:53:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.ghidinelli.com/?p=429#comment-52937</guid>
		<description>Did you alter both the uuidtest and uuidtest_ref tables? The &lt;a href=&quot;http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/tablecmds.c?rev=1.274;content-type=text%2Fx-cvsweb-markup&quot; rel=&quot;nofollow&quot;&gt;source of the alter table command&lt;/a&gt; says:

	/*
	 * Foreign key constraints are checked in a final pass, since (a) it&#039;s
	 * generally best to examine each one separately, and (b) it&#039;s at least
	 * theoretically possible that we have changed both relations of the
	 * foreign key, and we&#039;d better have finished both rewrites before we try
	 * to read the tables.
	 */

But the alter table commands were refactored significantly in the current version so you may need to get a copy of head to get this working.</description>
		<content:encoded><![CDATA[<p>Did you alter both the uuidtest and uuidtest_ref tables? The <a href="http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/tablecmds.c?rev=1.274;content-type=text%2Fx-cvsweb-markup" rel="nofollow">source of the alter table command</a> says:</p>
<p>	/*<br />
	 * Foreign key constraints are checked in a final pass, since (a) it&#8217;s<br />
	 * generally best to examine each one separately, and (b) it&#8217;s at least<br />
	 * theoretically possible that we have changed both relations of the<br />
	 * foreign key, and we&#8217;d better have finished both rewrites before we try<br />
	 * to read the tables.<br />
	 */</p>
<p>But the alter table commands were refactored significantly in the current version so you may need to get a copy of head to get this working.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.ghidinelli.com/2008/12/16/converting-from-uuids-to-guids/comment-page-1#comment-52936</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Tue, 16 Dec 2008 19:58:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.ghidinelli.com/?p=429#comment-52936</guid>
		<description>I got a little further and tried with a foreign key:

&lt;pre&gt;&lt;code&gt;
CREATE TABLE uuidtest (
	uidTest CHAR(35) NOT NULL PRIMARY KEY
) WITHOUT OIDS;

INSERT INTO uuidtest VALUES (&#039;C5F25CC3-1D72-822B-795706E5A2C8F6B1&#039;);
INSERT INTO uuidtest VALUES (&#039;A5F01CC3-1D72-822B-795706E5A2C8F6B1&#039;);
INSERT INTO uuidtest VALUES (&#039;D6F25CC3-1D72-822B-795706E5A2C8F6B1&#039;);
INSERT INTO uuidtest VALUES (&#039;C5FC2CC3-1D72-822B-795706E5A2C8F6B1&#039;);
INSERT INTO uuidtest VALUES (&#039;E5F25CC3-1D72-822B-795706E5A2C8F6B1&#039;);

create table uuidtest_ref (
	uidTest char(35) not null references uuidtest(uidTest) on update cascade on delete cascade
) WITHOUT OIDS;

INSERT INTO uuidtest_ref VALUES (&#039;C5F25CC3-1D72-822B-795706E5A2C8F6B1&#039;);
INSERT INTO uuidtest_ref VALUES (&#039;A5F01CC3-1D72-822B-795706E5A2C8F6B1&#039;);
&lt;/code&gt;&lt;/pre&gt;

But trying to run the ALTER TYPE doesn&#039;t work:

&lt;code&gt;
ERROR: foreign key constraint &quot;uuidtest_ref_uidtest_fkey&quot; cannot be implemented
SQL state: 42804
Detail: Key columns &quot;uidtest&quot; and &quot;uidtest&quot; are of incompatible types: character and uuid.
&lt;/code&gt;

I tried this with a transaction block, with deferred constraints, with disabled triggers, etc.  I think the only option is to eliminate the FK and recreate it?</description>
		<content:encoded><![CDATA[<p>I got a little further and tried with a foreign key:</p>
<pre><code>
CREATE TABLE uuidtest (
	uidTest CHAR(35) NOT NULL PRIMARY KEY
) WITHOUT OIDS;

INSERT INTO uuidtest VALUES ('C5F25CC3-1D72-822B-795706E5A2C8F6B1');
INSERT INTO uuidtest VALUES ('A5F01CC3-1D72-822B-795706E5A2C8F6B1');
INSERT INTO uuidtest VALUES ('D6F25CC3-1D72-822B-795706E5A2C8F6B1');
INSERT INTO uuidtest VALUES ('C5FC2CC3-1D72-822B-795706E5A2C8F6B1');
INSERT INTO uuidtest VALUES ('E5F25CC3-1D72-822B-795706E5A2C8F6B1');

create table uuidtest_ref (
	uidTest char(35) not null references uuidtest(uidTest) on update cascade on delete cascade
) WITHOUT OIDS;

INSERT INTO uuidtest_ref VALUES ('C5F25CC3-1D72-822B-795706E5A2C8F6B1');
INSERT INTO uuidtest_ref VALUES ('A5F01CC3-1D72-822B-795706E5A2C8F6B1');
</code></pre>
<p>But trying to run the ALTER TYPE doesn&#8217;t work:</p>
<p><code><br />
ERROR: foreign key constraint "uuidtest_ref_uidtest_fkey" cannot be implemented<br />
SQL state: 42804<br />
Detail: Key columns "uidtest" and "uidtest" are of incompatible types: character and uuid.<br />
</code></p>
<p>I tried this with a transaction block, with deferred constraints, with disabled triggers, etc.  I think the only option is to eliminate the FK and recreate it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jochem van Dieten</title>
		<link>http://www.ghidinelli.com/2008/12/16/converting-from-uuids-to-guids/comment-page-1#comment-52935</link>
		<dc:creator>Jochem van Dieten</dc:creator>
		<pubDate>Tue, 16 Dec 2008 19:20:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.ghidinelli.com/?p=429#comment-52935</guid>
		<description>You should be able to wrap the whole conversion in one statement which should of course be faster. And instead of deferring foreign key constraints you can temporarily disable them:

ALTER TABLE uuidTest DISABLE TRIGGER ALL;

ALTER TABLE uuidtest ALTER COLUMN uidTest TYPE uuid USING CAST(regexp_replace(uidTest, &#039;([A-Z0-9]{4})([A-Z0-9]{12})&#039;, &#039;\\1-\\2&#039;) AS uuid);

ALTER TABLE uuidTest ENABLE TRIGGER ALL;</description>
		<content:encoded><![CDATA[<p>You should be able to wrap the whole conversion in one statement which should of course be faster. And instead of deferring foreign key constraints you can temporarily disable them:</p>
<p>ALTER TABLE uuidTest DISABLE TRIGGER ALL;</p>
<p>ALTER TABLE uuidtest ALTER COLUMN uidTest TYPE uuid USING CAST(regexp_replace(uidTest, &#8216;([A-Z0-9]{4})([A-Z0-9]{12})&#8217;, &#8216;\\1-\\2&#8242;) AS uuid);</p>
<p>ALTER TABLE uuidTest ENABLE TRIGGER ALL;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brian</title>
		<link>http://www.ghidinelli.com/2008/12/16/converting-from-uuids-to-guids/comment-page-1#comment-52934</link>
		<dc:creator>brian</dc:creator>
		<pubDate>Tue, 16 Dec 2008 19:01:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.ghidinelli.com/?p=429#comment-52934</guid>
		<description>@Andrew - that worked!  Awesome suggestion!  I do relatively little column altering so I never looked to see if there were additional options.  Here&#039;s the results:

&lt;code&gt;
SELECT * from uuidtest;
&quot;c5f25cc3-1d72-822b-7957-06e5a2c8f6b1&quot;
&quot;a5f01cc3-1d72-822b-7957-06e5a2c8f6b1&quot;
&quot;d6f25cc3-1d72-822b-7957-06e5a2c8f6b1&quot;
&quot;c5fc2cc3-1d72-822b-7957-06e5a2c8f6b1&quot;
&quot;e5f25cc3-1d72-822b-7957-06e5a2c8f6b1&quot;
&lt;/code&gt;

And this test returned Yes:

#yesNoFormat(isValid(&#039;guid&#039;, &quot;c5f25cc3-1d72-822b-7957-06e5a2c8f6b1&quot;))#

There are some Transfer issues to solve but otherwise this makes it feasible.  Thanks again!</description>
		<content:encoded><![CDATA[<p>@Andrew &#8211; that worked!  Awesome suggestion!  I do relatively little column altering so I never looked to see if there were additional options.  Here&#8217;s the results:</p>
<p><code><br />
SELECT * from uuidtest;<br />
"c5f25cc3-1d72-822b-7957-06e5a2c8f6b1"<br />
"a5f01cc3-1d72-822b-7957-06e5a2c8f6b1"<br />
"d6f25cc3-1d72-822b-7957-06e5a2c8f6b1"<br />
"c5fc2cc3-1d72-822b-7957-06e5a2c8f6b1"<br />
"e5f25cc3-1d72-822b-7957-06e5a2c8f6b1"<br />
</code></p>
<p>And this test returned Yes:</p>
<p>#yesNoFormat(isValid(&#8217;guid&#8217;, &#8220;c5f25cc3-1d72-822b-7957-06e5a2c8f6b1&#8243;))#</p>
<p>There are some Transfer issues to solve but otherwise this makes it feasible.  Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.ghidinelli.com/2008/12/16/converting-from-uuids-to-guids/comment-page-1#comment-52933</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Tue, 16 Dec 2008 18:31:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.ghidinelli.com/?p=429#comment-52933</guid>
		<description>Have you tired?

ALTER TABLE uuidtest ALTER COLUMN uidTest TYPE uuid USING uidTest::uuid;

(I just found out about the USING keyword just recently: http://archives.postgresql.org/pgsql-sql/2008-11/msg00047.php)</description>
		<content:encoded><![CDATA[<p>Have you tired?</p>
<p>ALTER TABLE uuidtest ALTER COLUMN uidTest TYPE uuid USING uidTest::uuid;</p>
<p>(I just found out about the USING keyword just recently: <a href="http://archives.postgresql.org/pgsql-sql/2008-11/msg00047.php)" rel="nofollow">http://archives.postgresql.org/pgsql-sql/2008-11/msg00047.php)</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

