<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-35239393</id><updated>2011-07-08T05:26:13.393Z</updated><category term='Reviews'/><category term='PostgreSQL'/><category term='Windows'/><category term='Broadband'/><category term='osx'/><category term='networking'/><category term='Linux'/><category term='Mac'/><title type='text'>Peter Mount's Blog</title><subtitle type='html'>Various ramblings about virtually everything</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://petermount.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://petermount.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Peter Mount</name><uri>http://www.blogger.com/profile/17966909742079692030</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://1.bp.blogspot.com/_r5bHuLcjRG4/SVdbfyh4yZI/AAAAAAAAJrM/1sFafl3Wjbg/S220/IMG_4101.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-35239393.post-1340756690411408970</id><published>2010-02-02T19:49:00.000Z</published><updated>2010-02-02T19:49:16.361Z</updated><title type='text'>Merging blogs</title><content type='html'>With several things happening with my other blog and open source projects, I'm consolidating my blogs into one and moving to wordpress.&lt;br /&gt;
&lt;br /&gt;
The new combined blog is now online at &lt;a href="http://blog.retep.org/"&gt;http://blog.retep.org/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35239393-1340756690411408970?l=petermount.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://petermount.blogspot.com/feeds/1340756690411408970/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35239393&amp;postID=1340756690411408970' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/1340756690411408970'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/1340756690411408970'/><link rel='alternate' type='text/html' href='http://petermount.blogspot.com/2010/02/merging-blogs.html' title='Merging blogs'/><author><name>Peter Mount</name><uri>http://www.blogger.com/profile/17966909742079692030</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://1.bp.blogspot.com/_r5bHuLcjRG4/SVdbfyh4yZI/AAAAAAAAJrM/1sFafl3Wjbg/S220/IMG_4101.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35239393.post-6596489991302459355</id><published>2009-07-11T08:19:00.004Z</published><updated>2009-07-11T08:29:52.710Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mac'/><category scheme='http://www.blogger.com/atom/ns#' term='osx'/><category scheme='http://www.blogger.com/atom/ns#' term='networking'/><title type='text'>Turn your Mac into a Wifi Base Station</title><content type='html'>&lt;p&gt;
Some people like myself use mobile broadband for their internet connection, either because it’s the only option where they live or like me have had enough of BT (in the UK you usually still need BT for the physical line regardless of the ISP).
&lt;/p&gt;

&lt;p&gt;
Now with the various dongles they work fine on the the local machine and for the local wired network its usually as simple as turning on Internet Sharing (for the 3 network you have to do &lt;a href="http://petermount.blogspot.com/2009/02/connecting-to-both-local-lan-and-3-3g_2773.html"&gt;things differently&lt;/a&gt; due to them using a special profile). The problem comes to when you want to share the connection via wifi - but don’t have a wifi router.
&lt;/p&gt;

&lt;p&gt;
On Linux boxes some wifi chipsets support base station mode but things become complicated due to having to configure the card, the firmware etcetera... but what about on a Mac? All recent Mac’s have AirPort cards so can a Mac act as a base station?
&lt;/p&gt;

&lt;p&gt;
To put it simply, yes and it’s supported as standard (I’m using OSX10.5.7). Not only that it can be enabled from a couple of extra clicks.
&lt;/p&gt;

&lt;p&gt;
First open System Preferences and select Sharing:
&lt;/p&gt;

&lt;img src="http://lh4.ggpht.com/_r5bHuLcjRG4/SlhLDmsJZMI/AAAAAAAAPfo/y3nPgWKZrmc/s800/syspref.jpg" /&gt;

&lt;p&gt;
Next Select (not check) Internet Sharing and make sure AirPort is turned on (I also have Ethernet enabled as well).
&lt;/p&gt;

&lt;img src="http://lh5.ggpht.com/_r5bHuLcjRG4/SlhLEKzgjaI/AAAAAAAAPfw/MOl50AVgfwc/s800/internetSharing.jpg" /&gt;

&lt;p&gt;
Now at this point when you turn on sharing the WiFi connection will be open to anyone - so it’s probably advisable to turn on encryption by Selecting AirPort Options:
&lt;/p&gt;

&lt;img src="http://lh5.ggpht.com/_r5bHuLcjRG4/SlhLDUc30TI/AAAAAAAAPfg/fmwLkgxGqS0/s800/webEncryption.jpg" /&gt;

&lt;p&gt;
That’s all there is to it. You simply turn it on by turning Internet Sharing on and pressing start.
&lt;/p&gt;

&lt;img src="http://lh4.ggpht.com/_r5bHuLcjRG4/SlhLDDYXTHI/AAAAAAAAPfY/dDt2sLPB9NY/s800/final.jpg" /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35239393-6596489991302459355?l=petermount.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://petermount.blogspot.com/feeds/6596489991302459355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35239393&amp;postID=6596489991302459355' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/6596489991302459355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/6596489991302459355'/><link rel='alternate' type='text/html' href='http://petermount.blogspot.com/2009/07/turn-your-mac-into-wifi-base-station.html' title='Turn your Mac into a Wifi Base Station'/><author><name>Peter Mount</name><uri>http://www.blogger.com/profile/17966909742079692030</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://1.bp.blogspot.com/_r5bHuLcjRG4/SVdbfyh4yZI/AAAAAAAAJrM/1sFafl3Wjbg/S220/IMG_4101.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_r5bHuLcjRG4/SlhLDmsJZMI/AAAAAAAAPfo/y3nPgWKZrmc/s72-c/syspref.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35239393.post-7297078854317591188</id><published>2009-02-28T16:24:00.001Z</published><updated>2009-02-28T18:13:47.108Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Reviews'/><category scheme='http://www.blogger.com/atom/ns#' term='Mac'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Nikkai A88JB FreeView PVR</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Maplin currently have some special offers on at the moment and one of them is the Nikkai A88JB USB PVR Digital TV Receiver for £39.99. Now I wasn’t really in the market for a new receiver but what caught my eye was that, unlike other standalone Freeview boxes with a card slot or usb port, this one supposedly records onto an external HD connected to the USB port - so I thought I’d give it a try.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;First the manual - what crap. It looks like it’s a photocopy of some original written in the usual pigeon english you’d expect of something mass made in China.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;As for the unit, it doesn’t look that well built with three buttons on the front (Power, Channel Up and Down) and a display showing the time when in standby or the channel number. On the right hand side there’s a cover which when opened shows the SD/MMC slot and the USB port.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;img src="http://lh6.ggpht.com/_r5bHuLcjRG4/Sal9InIe43I/AAAAAAAAM4o/lxQdr5zFr3E/s400/IMG00004-20090228-1633.jpg" /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;View of the unit sitting on top of my old PS2.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: italic 12.0px Helvetica"&gt;The white cable is plugged in to the USB port and connects an old USB Harddrive to the unit.&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Once plugged in it runs relatively well. Scanning for channels is quick and when in use it’s a lot more responsive than my existing Freeview box (built into the TV).(a lot quicker than the one I’ve been using) and the user interface is not the best I’ve seen - I’ve seen better with units far cheaper than this one, but at least it works.Now apparently it has text support but I can’t get that to work, and you cannot record radio (no big deal there), but the main thing is the recording of programs.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Recording live TV is simple, just press REC and it records. To stop you’d have thought you would press the stop button next to it but no, it’s press REC again then confirm by pressing left and Enter - 3 button presses when there’s a button next to it!&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Playback from the unit appears fine as well, but the timer is sheer crap. You can only program in up to 8 timers and you can set them with the date, time and channel and if it occurs once, every day, week or year (why?). It takes me back to programming VHS recorders twenty years ago.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;So, now begs the question - can the recordings be played back on the Mac?&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Well, the files are stored on the HD as .mpg files and they are readable. However Quicktime doesn’t recognise it (this is with Perian installed). Not looking good so far. I then tried Media Player 10 that I have installed inside VMWare and again no go. Media Player plays the audio but could not find a video codec.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Not wanting to give up on 40 quid I then turned to good old Open Source.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;So I fired up &lt;a href="http://www.videolan.org/"&gt;VideoLan&lt;/a&gt; and tried playing the recorded program - presto it works.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;img src="http://lh5.ggpht.com/_r5bHuLcjRG4/Sal9IK-XhlI/AAAAAAAAM4g/J6XpmuufRUE/s800/mac.jpg" /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;A test recording being played with VLC on Mac OSX10.5&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Now if VideoLan works on the Mac then will it work with Linux? Yep even on Linux it will play a recording :-)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;img src="http://lh5.ggpht.com/_r5bHuLcjRG4/Sal9Hy4QW-I/AAAAAAAAM4Y/jFvYbWaBTb8/s800/linux.jpg" /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;A test recording being played with VLC running on Ubuntu 8.10&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;So all in all it seems that it might be a decent unit. The timers could do with some work, and it looks ugly with the USB cable showing from the front (no rear USB port), but it might be a good buy - we’ll see.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;
&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;I’m going to set it up to record some shows during the next week (ones on whilst I’m at work) and see how it performs, so expect an update next week.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35239393-7297078854317591188?l=petermount.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://petermount.blogspot.com/feeds/7297078854317591188/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35239393&amp;postID=7297078854317591188' title='19 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/7297078854317591188'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/7297078854317591188'/><link rel='alternate' type='text/html' href='http://petermount.blogspot.com/2009/02/nikkai-a88jb-freeview-pvr.html' title='Nikkai A88JB FreeView PVR'/><author><name>Peter Mount</name><uri>http://www.blogger.com/profile/17966909742079692030</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://1.bp.blogspot.com/_r5bHuLcjRG4/SVdbfyh4yZI/AAAAAAAAJrM/1sFafl3Wjbg/S220/IMG_4101.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_r5bHuLcjRG4/Sal9InIe43I/AAAAAAAAM4o/lxQdr5zFr3E/s72-c/IMG00004-20090228-1633.jpg' height='72' width='72'/><thr:total>19</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35239393.post-3441527557944934901</id><published>2009-02-12T09:21:00.005Z</published><updated>2009-02-28T18:22:42.820Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mac'/><category scheme='http://www.blogger.com/atom/ns#' term='Broadband'/><title type='text'>Connecting to both local lan and 3's 3G Dongle on the Mac</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;A problem reported elsewhere on the net with 3’s 3G Broadband dongles is that while you are connected to the net it disconnects you from your local lan preventing you from accessing both. I presume its to prevent people from sharing the broadband without using their dedicated router which they sell to connect the dongle direct to the lan.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Anyhow the main problem for me is that when using a VPN with the dongle, the Mac could connect to the remote network fine, but Windows or Linux running inside VMWare could not as the dongle broke the network. This was causing me problems as I need to access MSSQL on the odd occasion.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Anyhow I’ve managed to figure out a way to allow the local lan to be connected at the same time with the dongle. In fact it’s so simple it’s stupid and I’m surprised no one has documented this anywhere else online - at least I never found it and various forums I’ve seen this question on don’t have this solution.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;The trick is:&lt;/p&gt;
&lt;ol style="list-style-type: decimal"&gt;
&lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Connect to the net&lt;/li&gt;
&lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Open &lt;span style="font: italic 12.0px Helvetica"&gt;System Preferences&lt;/span&gt; and click on &lt;span style="font: italic 12.0px Helvetica"&gt;Network&lt;/span&gt;&lt;/li&gt;
&lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;You should see &lt;span style="font: italic 12.0px Helvetica"&gt;3Connect&lt;/span&gt; in the Location dropdown - if not make sure it’s visible&lt;/li&gt;
&lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;On the left you should see the list of interfaces (Ethernet, Bluetooth etc) all greyed out.&lt;/li&gt;
&lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Click on the &lt;span style="font: bold 12.0px Helvetica"&gt;+&lt;/span&gt; at the bottom left corner of that list and a popup appears.&lt;/li&gt;
&lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Select &lt;span style="font: bold 12.0px Helvetica"&gt;Ethernet&lt;/span&gt; in the Interface dropdown then press &lt;span style="font: bold 12.0px Helvetica"&gt;Create&lt;/span&gt;&lt;/li&gt;
&lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Now if you use DHCP like I do thats it - DHCP will kick in within a few seconds.&lt;/li&gt;
&lt;li style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;If you don’t use DHCP then simply configure the new interface with a local static IP.&lt;/li&gt;
&lt;/ol&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;That’s it - nice and simple. Your milage may vary with this, but at least it worked for me.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Here’s the screenshot where you can see Ethernet 2 connected and the Dongle (disconnected when I took this screenshot):&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;img src="http://lh3.ggpht.com/_r5bHuLcjRG4/SamAZlybnpI/AAAAAAAAM5c/CamtvKq6Yu8/s400/3g.jpg" /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35239393-3441527557944934901?l=petermount.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://petermount.blogspot.com/feeds/3441527557944934901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35239393&amp;postID=3441527557944934901' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/3441527557944934901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/3441527557944934901'/><link rel='alternate' type='text/html' href='http://petermount.blogspot.com/2009/02/connecting-to-both-local-lan-and-3-3g_2773.html' title='Connecting to both local lan and 3&amp;#39;s 3G Dongle on the Mac'/><author><name>Peter Mount</name><uri>http://www.blogger.com/profile/17966909742079692030</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://1.bp.blogspot.com/_r5bHuLcjRG4/SVdbfyh4yZI/AAAAAAAAJrM/1sFafl3Wjbg/S220/IMG_4101.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_r5bHuLcjRG4/SamAZlybnpI/AAAAAAAAM5c/CamtvKq6Yu8/s72-c/3g.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35239393.post-7711468564923749310</id><published>2009-01-04T12:44:00.000Z</published><updated>2009-01-04T12:45:49.097Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>How to change the Blue Screen of Death into another colour</title><content type='html'>We have all had a BSOD (Blue Screen Of Death) when something catastrophic has happened with Windows - which is usually when you try to do anything useful, but if you get tired of it being the standard Blue or if you have a visual imparement so the default settings are useless for you, here’s how to change it.

First open the SYSTEM.INI file found in the %systemroot% folder (usually C:\Windows) and locate the [386enh] section.

Add the following two entries if they are not present:

&lt;span style="font-size: 11pt;"&gt;MessageBackColor=
MessageTextColor=
&lt;/span&gt;
Each of those entries take a single hexadecimal digit defining the colour:
&lt;ul style="list-style-type: disc"&gt;&lt;li&gt;0 - Black&lt;/li&gt;&lt;li&gt;1 - Blue&lt;/li&gt;&lt;li&gt;2 - Green&lt;/li&gt;&lt;li&gt;3 - Cyan&lt;/li&gt;&lt;li&gt;4 - Red&lt;/li&gt;&lt;li&gt;5 - Magenta&lt;/li&gt;&lt;li&gt;6 - Yellow&lt;/li&gt;&lt;li&gt;7 - White&lt;/li&gt;&lt;li&gt;8 - Grey&lt;/li&gt;&lt;li&gt;9 - Bright blue&lt;/li&gt;&lt;li&gt;A - Bright green&lt;/li&gt;&lt;li&gt;B - Bright cyan&lt;/li&gt;&lt;li&gt;C - Bright red&lt;/li&gt;&lt;li&gt;D - Bright magenta&lt;/li&gt;&lt;li&gt;E - Bright yellow&lt;/li&gt;&lt;li&gt;F - Bright white&lt;/li&gt;&lt;/ul&gt;So to change it to Cyan and bright white text, then use the following:

&lt;span style="font-size: 11pt;"&gt;MessageBackColor=3
MessageTextColor=F
&lt;/span&gt;
The settings will take effect the next time you restart Windows.

NB: The values must be in upper case hence using F and not f in the above example.
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35239393-7711468564923749310?l=petermount.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://petermount.blogspot.com/feeds/7711468564923749310/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35239393&amp;postID=7711468564923749310' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/7711468564923749310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/7711468564923749310'/><link rel='alternate' type='text/html' href='http://petermount.blogspot.com/2009/01/how-to-change-blue-screen-of-death-into.html' title='How to change the Blue Screen of Death into another colour'/><author><name>Peter Mount</name><uri>http://www.blogger.com/profile/17966909742079692030</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://1.bp.blogspot.com/_r5bHuLcjRG4/SVdbfyh4yZI/AAAAAAAAJrM/1sFafl3Wjbg/S220/IMG_4101.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35239393.post-3428718284320226265</id><published>2008-12-29T15:06:00.001Z</published><updated>2009-02-28T18:24:19.991Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='PostgreSQL'/><title type='text'>Sets and Nodes with PostgreSQL</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;At times you need to be able gather information into Sets where an entry can contain one or more entries or sets, or Nodes where an entry has child nodes each of whom can contain their own children. For me it’s usually a geographical tree (Continent, Country, County, Town) or permission roles (Administrator, Moderator, User). Although this is documented elsewhere on the net, here’s how I do this in PostgreSQL utilising pl/pgsql functions.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;The tree of nodes consists of one entry in the table per node, with the root node at the top of the tree. Selects on the table are fast, but updates are expensive. As the data contained in the tree rarely changes, this is perfectly fine for most purposes.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;For the first example, I’m going to use a geographical tree, so we will have at the end of the exercise the following tree:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;img src="http://lh6.ggpht.com/_r5bHuLcjRG4/SVj8y2FmP4I/AAAAAAAAJuI/iN4ww0PMK3g/s800/nodes.YIb3lxdIBHE1.jpg" /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;First we need a table to store the data. The following SQL Schema defines the node table and inserts the root. Apart from this instance, you should only use the pl/pgsql functions to modify this table:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE SEQUENCE nodeseq;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE TABLE node (&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;nodeid BIGINT NOT NULL,&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;l BIGINT NOT NULL,&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;r BIGINT NOT NULL,&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;d INTEGER NOT NULL, -- the depth of this node, 0 = root&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;n name NOT NULL,&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;PRIMARY KEY (nodeid)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE INDEX node_l ON node(l);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE INDEX node_r ON node(r);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE INDEX node_lr ON node(l,r);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE INDEX node_lrd ON node(l,r,d);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE INDEX node_ln ON node(l,n);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE INDEX node_rn ON node(r,n);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE INDEX node_lrn ON node(l,r,n);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE INDEX node_lrdn ON node(l,r,d,n);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;-- The root node (0) preinitialised for the structure to work.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;INSERT INTO node (nodeid,l,r,d,n) VALUES (0,1,2,0,'root');&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Here we have the table initialised with the root node. At first it has the nodeid of 0, l=1, r=2 and d=0. Over time the l and r values will change as nodes are added to the tree.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Now for the first set of pl/pgsql functions. This set of functions handle retrieval of nodes from the tree based on certain criteria. I’ll only show the function definitions for now as I’ll show how to use these later in this article.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;Retrieving a node by its nodeid&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE OR REPLACE FUNCTION node_get( parentid BIGINT )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;RETURNS node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;AS $$&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;DECLARE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;n&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;BEGIN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;SELECT *&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;INTO n&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;FROM node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;WHERE nodeid=parentid;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF NOT FOUND THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RAISE EXCEPTION 'Node % not found', parentid;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;RETURN n;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;END&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;$$ LANGUAGE 'plpgsql';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;Is the node a leaf, i.e. it contains no children&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE OR REPLACE FUNCTION node_isleaf( childnodeid BIGINT )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;RETURNS boolean&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;AS $$&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;DECLARE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;child node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;BEGIN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;child := node_get( childnodeid );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;RETURN (child.r-child.l)==1;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;END&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;$$ LANGUAGE 'plpgsql';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;Does one node contain the other&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE OR REPLACE FUNCTION node_contains( parentnodeid BIGINT, childnodeid BIGINT )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;RETURNS boolean&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;AS $$&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;BEGIN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;RETURN node_contains( node_get( parentnodeid ), node_get( childnodeid ) );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;END&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;$$ LANGUAGE 'plpgsql';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE OR REPLACE FUNCTION node_contains( parentnode node, childnode node )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;RETURNS boolean&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;AS $$&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;BEGIN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;RETURN parentnode.l&amp;lt;=childnode.l AND parentnode.r&amp;gt;=childnode.r;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;END&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;$$ LANGUAGE 'plpgsql';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;Retrieve the parent of a node&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE OR REPLACE FUNCTION node_parent( rootnodeid BIGINT, childnodeid BIGINT )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;RETURNS node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;AS $$&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;DECLARE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;rootnode&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;startnode &lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;parentnode&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;BEGIN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF childnodeid = rootnodeid THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RAISE EXCEPTION 'Node % has no parent', childnodeid;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- get the root&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;rootnode := node_get( rootnodeid );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- get the start&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;startnode := node_get( childnodeid );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- the root must contain the start&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF NOT node_contains( rootnode, startnode ) THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RAISE EXCEPTION 'Node % is not contained by the root node %', childnodeid, rootnodeid;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- The root is the parent&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF rootnode.d = (startnode.d-1) THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RETURN rootnode;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;SELECT *&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;INTO parentnode&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;FROM node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;WHERE l&amp;lt;startnode.l AND r&amp;gt;startnode.r AND d=startnode.d-1;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF NOT FOUND THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RAISE EXCEPTION 'Node % has no parent', childnodeid;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- the root must contain the parent&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF NOT node_contains( rootnode, parentnode ) THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RAISE EXCEPTION 'Node % has no parent', childnodeid;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;RETURN parentnode;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;END&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;$$ LANGUAGE 'plpgsql';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;Add a child node&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;This is probably the most important function as it adds a new node as a child to another and as such is the primary means of adding nodes to the tree.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE OR REPLACE FUNCTION node_addchild( parentid BIGINT, name NAME )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;RETURNS node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;AS $$&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;DECLARE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;parent&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;child &lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;tmp &lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;TEXT[];&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;BEGIN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- Validate name ensuring it contains no index&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;SELECT regexp_matches( name, E'([^\\]]+)(\\[([^\\[]+)\\]){0,1}' )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;INTO tmp;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF tmp[2] IS NOT NULL THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RAISE EXCEPTION 'Name % is invalid, it may not contain an index', name;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;parent := node_get( parentid );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;/* We allow same named children, but this would disallow it&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;SELECT *&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;INTO child&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;FROM node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;WHERE l &amp;gt; parent.l AND r &amp;lt; parent.r AND n = name;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF FOUND THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RAISE EXCEPTION 'The child % already exists under %', name, parentid;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;*/&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;UPDATE node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;SET r=r+2&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;WHERE r &amp;gt;= parent.r;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;UPDATE node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;SET l=l+2&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;WHERE l &amp;gt;= parent.r;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;INSERT INTO node (nodeid,l,r,d,n)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;VALUES (nextval('nodeseq'), parent.r, parent.r+1, parent.d+1, name);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;child := node_get( currval('nodeseq') );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;RETURN child;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;END;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;$$ LANGUAGE 'plpgsql';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Now using our example tree, the first thing we need to do is to add Europe to the tree as a child of the root. Now the root always has nodeid 0 so we call node_addchild( 0, ‘Europe’ ) to add a new node representing Europe:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l | r | d |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;n&lt;span class="Apple-converted-space"&gt;   &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+---+---+---+------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;0 | 1 | 2 | 0 | root&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node_addchild(0,'Europe');&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l | r | d | &lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;   &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+---+---+---+--------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;1 | 2 | 3 | 1 | Europe&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l | r | d | &lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;   &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+---+---+---+--------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;0 | 1 | 4 | 0 | root&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;1 | 2 | 3 | 1 | Europe&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(2 rows)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Here you’ll notice that after the call to node_addchild() it returned the new node (nodeid 1) and updated the root node so it’s l and r fields bound those of it’s children.&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;We’ll now add the other nodes except the towns:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node_addchild(1,'United Kingdom');&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l | r | d | &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;       &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+---+---+---+----------------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;2 | 3 | 4 | 2 | United Kingdom&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node_addchild(2,'Kent');&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l | r | d |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;n&lt;span class="Apple-converted-space"&gt;   &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+---+---+---+------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;3 | 4 | 5 | 3 | Kent&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node_addchild(2,'Sussex');&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l | r | d | &lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;   &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+---+---+---+--------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;4 | 6 | 7 | 3 | Sussex&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;Adding a node by it’s path&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Apart from node_addchild we can also add a node by it’s path. For Canterbury it’s path from Europe is “United Kingdom/Kent/Canterbury” so instead of having to find Kent, we can use the node_addchildbypath function:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;test=# select * from node_addchildbypath( 0, 1, 'United Kingdom/Kent/Canterbury' );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l | r | d | &lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;     &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+---+---+---+------------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;5 | 5 | 6 | 4 | Canterbury&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Here’s the node_addchildbypath function:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE OR REPLACE FUNCTION node_addchildbypath( rootnodeid BIGINT, parentid BIGINT, path TEXT )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;RETURNS node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;AS $$&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;DECLARE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;rootnode&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;parent&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;child &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;tmp &lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;TEXT[];&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;lastname&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;TEXT;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;path2 &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;TEXT;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;name2 &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;TEXT;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;BEGIN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;rootnode := node_get( rootnodeid );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;parent := node_get( parentid );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF NOT node_contains( rootnode, parent ) THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RAISE EXCEPTION 'Parent % is not contained by root %', parentid, rootnodeid;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- Extract the last path&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;SELECT regexp_split_to_array( path, E'\\/' )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;INTO tmp;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF array_upper( tmp, 1 ) = 1 THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;child := node_addchild( parentid, path );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;ELSE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;-- remove the tail element&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;name2 := tmp[ array_upper(tmp, 1 ) ];&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;path2 := substr( path, 0, length(path) - length( name2 ) );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;parent := node_findbypath( rootnodeid, parentid, path2 );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;child := node_addchild( parent.nodeid, name2 );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;RETURN child;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;END;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;$$ LANGUAGE 'plpgsql';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Now we’ll add the last set of towns to the tree:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node_addchildbypath( 0, 1, 'United Kingdom/Kent/Maidstone' );&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l | r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d | &lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;n&lt;span class="Apple-converted-space"&gt;     &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+---+----+---+-----------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;6 | 7 | 8 | 4 | Maidstone&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node_addchildbypath( 0, 1, 'United Kingdom/Kent/Tonbridge' );&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d | &lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;n&lt;span class="Apple-converted-space"&gt;     &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+----+----+---+-----------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;7 | 9 | 10 | 4 | Tonbridge&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node_addchildbypath( 0, 1, 'United Kingdom/Sussex/Arundel' );&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d |&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;   &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+----+----+---+---------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;8 | 13 | 14 | 4&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| Arundel&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span style="font: bold 11.0px Courier New"&gt;test=# select * from node;&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d | &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;       &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+----+----+---+----------------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;6 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;7 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;8 | 4 | Maidstone&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;3 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;4 | 11 | 3 | Kent&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;7 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;9 | 10 | 4 | Tonbridge&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;0 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;1 | 18 | 0 | root&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;1 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;2 | 17 | 1 | Europe&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;2 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;3 | 16 | 2 | United Kingdom&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;4 | 12 | 15 | 3 | Sussex&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;8 | 13 | 14 | 4 | Arundel&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;5 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;5 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;6 | 4 | Canterbury&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(9 rows)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;Retrieving the children of a node&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;When handling sets, you can simply use the following to return all entries contained by a node - here we will ask for all nodes within the United Kingdom:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;test=# select * from node_get(2);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l | r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d | &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;       &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+---+----+---+----------------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;2 | 3 | 16 | 2 | United Kingdom&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;test=# select * from node where l &amp;gt; 3 and r &amp;lt; 16;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d | &lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;     &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+----+----+---+------------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;6 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;7 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;8 | 4 | Maidstone&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;3 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;4 | 11 | 3 | Kent&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;7 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;9 | 10 | 4 | Tonbridge&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;4 | 12 | 15 | 3 | Sussex&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;8 | 13 | 14 | 4 | Arundel&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;5 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;5 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;6 | 4 | Canterbury&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(6 rows)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Now this is fine for sets, but when dealing with a tree we usually need to know those nodes immediately beneath the node, in this case the counties. This is where the node_children function is handy:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;test=# select * from node_children(2);&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d | &lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;   &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+----+----+---+--------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;3 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;4 | 11 | 3 | Kent&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;4 | 12 | 15 | 3 | Sussex&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(2 rows)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Here’s the definition for node_children - here you’ll notice it’s similar to retrieving the contained entries but it now uses the d column:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE OR REPLACE FUNCTION node_children( parentid BIGINT )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;RETURNS SETOF node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;AS $$&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;DECLARE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;parent node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;r node%rowtype;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;BEGIN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;parent := node_get( parentid );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;FOR r&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;IN SELECT *&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;            &lt;/span&gt;FROM node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;            &lt;/span&gt;WHERE l BETWEEN parent.l AND parent.r&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;                &lt;/span&gt;AND d = parent.d+1&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;            &lt;/span&gt;ORDER BY n, nodeid&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;LOOP&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RETURN NEXT r;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END LOOP;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;RETURN;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;END;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;$$ LANGUAGE 'plpgsql';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;&lt;span style="font: bold 12.0px Helvetica"&gt;Deleting nodes&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Deleting a node is not as simple as simply deleting the entry from the table. What we have to do is delete the entry including all of it’s children and then close the gap in the l &amp;amp; r columns where the deleted entries used to be. To handle this we have the node_deleteTree function. For this example we’ll add a new County, town then delete them from the tree:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;test=# select * from node_addchildbypath( 0, 1, 'United Kingdom/Cornwall' );NOTICE:&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;name2 = CornwallNOTICE:&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;path2 = United Kingdom&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d |&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;n&lt;span class="Apple-converted-space"&gt;     &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+----+----+---+----------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;9 | 16 | 17 | 3 | Cornwall&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;test=# select * from node_addchildbypath( 0, 1, 'United Kingdom/Cornwall/St Austell' );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d | &lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;     &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+----+----+---+------------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;     &lt;/span&gt;10 | 17 | 18 | 4 | St Austell&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;test=# select * from node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d | &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;       &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+----+----+---+----------------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;6 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;7 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;8 | 4 | Maidstone&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;3 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;4 | 11 | 3 | Kent&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;7 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;9 | 10 | 4 | Tonbridge&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;4 | 12 | 15 | 3 | Sussex&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;8 | 13 | 14 | 4 | Arundel&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;0 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;1 | 22 | 0 | root&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;1 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;2 | 21 | 1 | Europe&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;2 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;3 | 20 | 2 | United Kingdom&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;9 | 16 | 19 | 3 | Cornwall&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;     &lt;/span&gt;10 | 17 | 18 | 4 | St Austell&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;5 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;5 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;6 | 4 | Canterbury&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(11 rows)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;test=# select node_deleteTree( 9 );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;node_deletetree&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;-----------------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;               &lt;/span&gt;2&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(1 row)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;test=# select * from node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;nodeid | l&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| r&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;| d | &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;n &lt;span class="Apple-converted-space"&gt;       &lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;--------+----+----+---+----------------&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;6 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;7 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;8 | 4 | Maidstone&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;3 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;4 | 11 | 3 | Kent&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;7 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;9 | 10 | 4 | Tonbridge&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;4 | 12 | 15 | 3 | Sussex&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;8 | 13 | 14 | 4 | Arundel&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;0 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;1 | 18 | 0 | root&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;1 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;2 | 17 | 1 | Europe&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;2 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;3 | 16 | 2 | United Kingdom&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;5 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;5 |&lt;span class="Apple-converted-space"&gt;  &lt;/span&gt;6 | 4 | Canterbury&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;(9 rows)&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;Here’s the definition for node_deleteTree:&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;CREATE OR REPLACE FUNCTION node_deleteTree( oldnodeid BIGINT )&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;RETURNS INTEGER&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;AS $$&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;DECLARE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;oldnode node;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;c &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;INTEGER := 0;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;d &lt;span class="Apple-converted-space"&gt;      &lt;/span&gt;INTEGER;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;BEGIN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- Cannot delete the root&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;IF oldnodeid = 0 THEN&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;RAISE EXCEPTION 'Cannot delete the root';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;END IF;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- Select the node we are deleting&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;oldnode := node_get( oldnodeid );&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- delete the node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;DELETE FROM node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;WHERE l BETWEEN oldnode.l AND oldnode.r;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;GET DIAGNOSTICS c = ROW_COUNT;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;-- now close the gap between l and r, d is the size of the gap to remove&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;d := oldnode.r - oldnode.l + 1;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;UPDATE node&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;SET l = CASE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;                &lt;/span&gt;WHEN l &amp;gt; oldnode.l&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;                    &lt;/span&gt;THEN l - d&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;                &lt;/span&gt;ELSE l&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;            &lt;/span&gt;END,&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;            &lt;/span&gt;r = CASE&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;                &lt;/span&gt;WHEN r &amp;gt; oldnode.l&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;                    &lt;/span&gt;THEN r - d&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;                &lt;/span&gt;ELSE r&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;            &lt;/span&gt;END&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;        &lt;/span&gt;WHERE l &amp;gt; oldnode.l&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;            &lt;/span&gt;OR r &amp;gt; oldnode.l;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New; min-height: 12.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;&lt;span class="Apple-converted-space"&gt;    &lt;/span&gt;RETURN c;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;END;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier New"&gt;$$ LANGUAGE 'plpgsql';&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"&gt;The full schema used by this article is available at &lt;a href="http://retep.org/blog/psql/nodes.txt"&gt;http://retep.org/blog/psql/nodes.txt&lt;/a&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35239393-3428718284320226265?l=petermount.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://petermount.blogspot.com/feeds/3428718284320226265/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35239393&amp;postID=3428718284320226265' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/3428718284320226265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/3428718284320226265'/><link rel='alternate' type='text/html' href='http://petermount.blogspot.com/2008/12/sets-and-nodes-with-postgresql.html' title='Sets and Nodes with PostgreSQL'/><author><name>Peter Mount</name><uri>http://www.blogger.com/profile/17966909742079692030</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://1.bp.blogspot.com/_r5bHuLcjRG4/SVdbfyh4yZI/AAAAAAAAJrM/1sFafl3Wjbg/S220/IMG_4101.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_r5bHuLcjRG4/SVj8y2FmP4I/AAAAAAAAJuI/iN4ww0PMK3g/s72-c/nodes.YIb3lxdIBHE1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35239393.post-8116353477046380115</id><published>2008-12-29T14:37:00.000Z</published><updated>2008-12-29T16:37:16.072Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Mac'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><title type='text'>Finding the process id of the process owning a port</title><content type='html'>Occasionally there’s time where you need to find out what process owns a port currently open.

On the Mac this can be done easily by using the following line - here we are looking for port 8080:

&lt;span style="font-size: 11pt;"&gt;ps u --no-heading -p  `netstat -nlept | awk '/[:]8080 / {split ($9,t,"/"); print t[1]}'` 2&amp;gt;/dev/null
&lt;/span&gt;
For windows you don’t have a decent shell (and cygwin would probably not work here), so you can use the following batch script to do the same:

&lt;span style="font-size: 11pt;"&gt;@echo off

for /F “usebackq tokens=5″ %%f in (`netstat -b -n ^| find “:%1″`) do call :process %%f
goto :eof

:process
tasklist /FI “PID eq %1″ /NH
&lt;/span&gt;
If the above code was called findport.bat then running findport 8080 would then find the process owning port 8080.
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35239393-8116353477046380115?l=petermount.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://petermount.blogspot.com/feeds/8116353477046380115/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35239393&amp;postID=8116353477046380115' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/8116353477046380115'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/8116353477046380115'/><link rel='alternate' type='text/html' href='http://petermount.blogspot.com/2008/12/finding-process-id-of-process-owning.html' title='Finding the process id of the process owning a port'/><author><name>Peter Mount</name><uri>http://www.blogger.com/profile/17966909742079692030</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://1.bp.blogspot.com/_r5bHuLcjRG4/SVdbfyh4yZI/AAAAAAAAJrM/1sFafl3Wjbg/S220/IMG_4101.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-35239393.post-115953707942156417</id><published>2006-09-29T13:24:00.000Z</published><updated>2006-09-29T13:37:59.430Z</updated><title type='text'>Well yet again I've succumbed</title><content type='html'>It's happened again - I've succumbed to another popular technology, this time blogging. It had to happen at some point, but after some resistence, here it is.

Over time, I'll be adding entries on how to do various things with Java programming, specifically in the areas of J2EE, Astronomy and DataBases, although I do dabble in some other areas like A.I. Chatbots e.t.c.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/35239393-115953707942156417?l=petermount.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://petermount.blogspot.com/feeds/115953707942156417/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=35239393&amp;postID=115953707942156417' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/115953707942156417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/35239393/posts/default/115953707942156417'/><link rel='alternate' type='text/html' href='http://petermount.blogspot.com/2006/09/well-yet-again-ive-succumbed.html' title='Well yet again I&apos;ve succumbed'/><author><name>Peter Mount</name><uri>http://www.blogger.com/profile/17966909742079692030</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='21' src='http://1.bp.blogspot.com/_r5bHuLcjRG4/SVdbfyh4yZI/AAAAAAAAJrM/1sFafl3Wjbg/S220/IMG_4101.JPG'/></author><thr:total>2</thr:total></entry></feed>
