Another cool feature I've recently discovered in PostgreSQL, although one available and documented for a long time, is table inheritance, which works almost exactly like object inheritance in object oriented programming. This simply means that you can have tables inheriting columns from parent tables.
Continue Reading »
Tags: PostgreSQL | 1 Comment
Sometimes when working on projects in both Linux and Windows, a file will end up with Windows newline characters, which show up as ^M in Vim. Annoying as this is, there's a quick fix to remove them in Vim using a regular expression replace:
:%s/<control-v><control-m>//g
Magically, all the ugly Windows newline characters are gone.
Tags: Linux, Vim | No Comments
I recently came across an amazing feature in PostgreSQL: the RETURNING clause. This clause allows you to return specific data as the result of an INSERT or UPDATE query.
Often, after doing one of these queries, I'm interested in getting some data, such as an autogenerated primary key field, or maybe some defaulted data (like a created timestamp). Normally, one would have to do an additional query to get this data. Using RETURNING, we can do our data manipulation and retrieval in the same query.
Example:
-- Return just the ID:
INSERT INTO books(name, author) VALUES('Awesome Book', 'Smart Author')
RETURNING book_id;
-- Return more than one column:
INSERT INTO books(name, author) VALUES ('Sweet Book', 'Other Author')
RETURNING book_id, created_on;
-- Return all the columns:
INSERT INTO books(name, author) VALUES ('Silly Book', 'Airhead Author')
RETURNING *;
In our code, we can simply treat the return value of the INSERT or UPDATE code like we would a SELECT statement.
Some things to keep in mind, though:
- If the
UPDATE query affects multiple rows, multiple rows of data will be returned. If no rows are affected, none will be returned.
- Normally the database would return the number of rows affected, but obviously we're overriding the return value of the query. Obviously we can check the number of rows returned by the query (like we would with a
SELECT) to get around this.
Tags: PostgreSQL | 1 Comment
I'm not afraid to admit it: I'm a fan of Gnome. I think KDE looks to cartoonish. I actually prefer using OpenBox with a slew of lightweight apps for window manager addons, but that because too much to maintain, and I have better things to do with my time.
It's hard to find a nice, clean set of decorations for Gnome that mesh well together. GDM theme, icons, wallpapers, GTK themes, etc that all blend well together to create a complete, polished look.
Recently I found the "Colors" theme set on Gnome Look.
GDM and Wallpapers: http://www.gnome-look.org/content/show.php/Arc-Colors+GDM-Walls?content=88305
GTK: http://www.gnome-look.org/content/show.php/Shiki-Colors?content=86717
Icons: http://www.gnome-look.org/content/show.php/GNOME-colors?content=82562
Nice and simple.
Tags: Gnome, Linux | No Comments
After watching the commercials for a year or so now and being a cardholder for 7 years, I thought I'd try designing my own Capital One credit card. I accidentally closed the browser window while trying to close something else and thought no big deal of it; I'd just reopen it, right? Wrong. I ran into this error message:
Oops…
We're sorry but it looks like you have recently visited the Image Card site. Please close this browser window and return to the original.
If you've already closed the original window, you will need to wait 3 hours before returning to the Image Card site. We're sorry for the inconvenience.
Eh? Wait 3 hours? I thought a simple matter of clearing my cookies would help. Nope. Still get the error.
I have no insight into the Capital One code, but as a web developer, I can really think of no reason one would have to wait 3 hours to use an application. Seriously, just provide a link that clears the session or cached server data. No big deal.
Capital One = FAIL. How about you guys lower my interest rate, too?
Tags: WTF | No Comments
Installed the Wordpress app for my BlackBerry. While it seems like a fun idea, typing HTML on this tiny, touch screen keyboard is a pain in the ass.
I don't think I'll be doing this often… or ever.
Tags: BlackBerry, Wordpress | No Comments
The other day I upgraded my Gentoo kernel (after realizing I was about 7 kernel updates old). After compiling and setting up Grub, I rebooted and received this error:
RAMDISK: Compressed image found at block 0
RAMDISK: ran out of compressed data
invalid compressed format (err=1)
UDF-fs: No VRS found
List of all partitions:
…
No file system could mount root, tried: …
Kernel panic - not syncing: VFS: unable to mount root fs on unknown-block(1,0)
After painful research, I finally discovered the problem: I ran out of space on my boot partition.
Apparently genkernel does not complain when it runs out of space to compile the kernel. It just stops and outputs the same message it would it if succeeded.
A "quick" use of parted to allocate more space to the boot partition, and re-compiling the kernel solved the problem. It's just sad that genkernel doesn't bother reporting the fact that it ran out of space.
Tags: Gentoo, Linux | No Comments
PostgreSQL 8.3 in Gentoo now creates the socket in /var/run/postgresql with stricter permissions, meaning that regular users cannot connect to the PostgreSQL server via command line. Emerging this package outputs a message about this that I initially missed when installing:
Please note that the standard location of the socket has changed from /tmp to /var/run/postgresql and you have to be in the 'postgres' group to access the socket.
This means that regular users who need access to the PostgreSQL server need to be added to the postgres group:
gpasswd -a user postgres
Tags: Gentoo, PostgreSQL | No Comments