Drupal database API query - row.update if exists, else row.insert
问题 I've been trying to run a query in drupal that'll update entries if they already exists or insert a new entry if it doesnt. The code looks like this at the moment: db_query("IF EXISTS (SELECT %d FROM {uc_posten_packages.pid}) UPDATE {uc_posten_packages} SET title = '%s', label = '%s', cost = '%d', length = '%d', width ='%d', height = '%d', weight = '%d' WHERE pid = %d ELSE INSERT INTO {uc_posten_packages} VALUES ('%d', '%s', '%s', '%d', '%d', '%d', '%d', '%d')",$id, $title, $label, $rate,