I am just about finished converting 84 stored procedures from MySQL to PostgreSQL functions. The only thing that has not been figured out is what to do with the replace() calls. The function doesn't exist in PostgreSQL. I am sure someone has had to do this before. Any suggestions?
set @sql="CREATE TABLE `tbodefcall...(An UnGodly Amount of code that creates tables ...honeid_cd_idx (PhoneID,CallDate);";
set @sql = Replace(@sql, 'tbodefcallback', concat('tbo_callback',_ProjectID) );
set @sql = Replace(@sql, 'tbodefcontact', concat('tbo_contact',_ProjectID) );
set @sql = Replace(@sql, 'tbodefscriptkvota', concat('tbo_scriptkvota',_ProjectID) );
set @sql = Replace(@sql, 'tbodefscript', concat('tbo_script',_ProjectID) );
set @sql = Replace(@sql, 'tbodeftermcode', concat('tbo_termcode',_ProjectID) );
set @sql = Replace(@sql, 'tbodefprojectlogon', concat('tbo_projectlogon',_ProjectID) );
set @sql = Replace(@sql, 'tbodefcomment', concat('tbo_comment',_ProjectID) );
set @sql = Replace(@sql, 'tbodefvoicerecorder', concat('tbo_voicerecorder',_ProjectID) );
s开发者_Python百科et @sql = Replace(@sql, 'tbodefquestiongroup', concat('tbo_questiongroup',_ProjectID) );
set @sql = Replace(@sql, 'tbodefquestion', concat('tbo_question',_ProjectID) );
Thanks for any help or suggestions. You guys have rocked in helping me through this project!
Postgresql does have the replace
function, at least in 8.4; which version are you using?
steve@steve@[local] =# select replace('create table tblfoo', 'tblfoo', 'tblfoo_44');
replace
------------------------
create table tblfoo_44
(1 row)
You're actually looking for an "upsert" command. In PostgreSQL you perform it the following way:
UPDATE ...;
IF NOT FOUND THEN -- UPDATE didn't touch anything
INSERT ...;
END IF;
精彩评论