PostgreSQL

Jul 01 2010

Update with records from another table


update subject_cloud set count = count + 1 from (select subject from subjects where sku = '9780520241329') as subs where subs.subject = subject_cloud.subject;

Mar 13 2009

Deleting from table where record is missing in other table


delete from product_categories where category IN (select distinct category from product_categories PC LEFT JOIN categories C on PC.category = C.code WHERE code is NULL);

MySQL example:

delete PC from product_categories PC left join products P on PC.sku = P.sku where P.sku is NULL;
delete C from categories C left join product_categories PC on C.code = PC.category where C.parent > 0 and PC.category is NULL;

MySQL example for multiple table update:

Jan 08 2009

Clone records with serial key


insert into form_elements(code,name,label,component,widget) select nextval('form_elements_code_seq'),name,label,'register',widget from form_elements where component = 'shippingaddress';

Feb 07 2008

Drupal and PostgreSQL

Drupal module authors appear to be oblivious of PostgreSQL as they are using MySQL specific functions all over the place. Most of these problems can be solved by mimic MySQL functions by adding custom PostgreSQL functions. Drupal itself supplies a bunch of routines through the database installation routine.

Aug 14 2007

Create UTF-8 Database

template1=# create database newsletter with owner = racke encoding 'utf8';
CREATE DATABASE