Postgresql Datatype mismatch default for column cannot be cast to type integer

When converting a table column from varchar to integer I ran into a problem.

SQLSTATE[42804]: Datatype mismatch: 7 ERROR:  default for column "column_name" cannot be cast to type integer

The solution I could find on (Stackoverflow)[http://stackoverflow.com/questions/13170570/change-type-of-varchar-field-to-integer-cannot-be-cast-automatically-to-type-i] was not working:

ALTER TABLE the_table ALTER COLUMN col_name TYPE integer USING (col_name::integer);

Looking closer at the error I realised – as is often the case – the error was indicating exactly what the problem was. The default of the column could not be converted.

Not knowing how to convert the default, I simply changed it to something that could be converted:

ALTER TABLE the_table ALTER COLUMN col_name SET DEFAULT 0;

Despite it being a varchar column, the integer value 0 was accepted. After which the earlier CAST worked.

img_5107

Install Debian wheezy-backports repository

The Debian backports repository contain packages or newer versions of packages that did not make it into the original release. You can read more about backports on the Debian website.

To install wheezy-backports you need to either add the repository line:

deb http://http.debian.net/debian wheezy-backports main

to your /etc/apt/sources.list file.

Alternatively you can create a new sources list file with this command (run as root):

# echo 'deb http://http.debian.net/debian wheezy-backports main' > /etc/apt/sources.list.d/wheezy-backports.list

Once installed, run apt-get update:

# apt-get update

Select individual packages to install:

# apt-get -t wheezy-backports install "package"

Photo credit: Giulio Turetta

andriod-cpu

Installing CyanogenMod onto a Samsung Galaxy S3 (International) – SIII / i9300 using Linux Mint 16 Petra (Ubuntu Saucy 13.10)

DISCLAIMER: Modifying or replacing your device’s software may void your device’s warranty, lead to data loss, hair loss, financial loss, privacy loss, security breaches, or other damage, and therefore must be done entirely at your own risk. I am not responsible for your actions. Good luck.

The new CyanogenMod installer requires Windows. Most of the manual tutorials assume you’re running Windows. Hopefully my summarised experience below will help other Linux users.

Continue reading

PostgreSQL functions and triggers

It is desirable to avoid using database functions. They are black boxes which gift only night horrors to unwary developers. A system is difficult to understand, maintain and debug when chunks of it lurk unseen in the DB.

Despite this – for certain features – using them does make sense. Provided the database function’s code is source controlled and huge lumps of comments referring to both the location and function of said code is spread evenly throughout the associated application code.

For example, in order to bill Ekaya agents accurately we needed a log of show house status changes, from upcoming to active to past or cancelled. Most of these changes were implemented in sweeping SQL statements that, while efficient at their own task, made it difficult to track individual changes.

Continue reading

classic date

Postgresql date formatting

Preamble

Formatting of data should only occur in the final steps of output. Until that point, and as a rule, internally data should remain in a base format that can easily be converted into many others – without being converted into another more basic format first.

For example Unix timestamp for dates or a floating point number for money. Both can readily be converted into more expressive formats without writing code to first parse or disassemble the initial format.

However in a situation where the flow is very specific and unlikely to ever be used to generate a different output it is permissible, even desirable, to generate data in the format it will be finally outputted.

Continue reading

whocharted

Bash script to download SXSW podcasts

For the last few years I have listened to the podcasts from SXSW while travelling to work or more recently while at gym.

Each year the number of podcasts has increased to the point where this year I am now too lazy to click through to every page and DownThemAll!. Besides it’s more fun to write a bash script to do the heavy lifting.

Continue reading