--goal: Dynamically update data in a table--the usual code.
---------------------------
--tablename Table Name
--feildname Field an array group
--feildvalue field Value Array
--returnvalue return value
Create or Replace functionf_update (tablenametext, Conditiontext, Feildnametext[], Feildvaluetext[], out ReturnValuetext) as $$DeclareMySQLtext; myIDinteger; Myresultinteger; Itemstext; Countsinteger; Iinteger;begincounts:=Array_length (Feildname,1); MySQL:='Update'||Quote_ident (tablename)||'Set'; forIinch 1.. Counts loop MySQL:=Mysql||Quote_ident (feildname[I])||'=" "||Feildvalue[I]||" ",'; EndLoop; MySQL:=substring(MySQL from 1 for(Char_length (MySQL)-1))|| 'where 1=1'||condition; ExecuteMySQL; GET Diagnostics Myresult:=Row_count; ifMyresult<>0 ThenReturnValue='{"Success": "Performing the update'||Mysql||'Success! "}'; ElseReturnValue='{"Success": "Performing the update'||Mysql||'failed! "}'; End if;End; $$ language plpgsql;--actual OperationCreate TableTest (IDinteger, nametext, Gen_time date,out returnvalue);Insert intoTest (Id,name,gen_time)Values(1,'Office','2017-08-19');SelectF_update ('Test','and id=1','{Name,gen_time}','{ssqhan,2017-08-20}');--The following results are obtained:
--The data inside is a bit different, it doesn't affect everyone.
--=======================================================================
-- I don't know if you're not aware that although gen_time is a date type, when you enter the time format at Update ,
-- The system automatically turns into date format
--does this mean that the time format, when passing parameters, is OK with the string directly?
-To be verified, put here today, and then have the opportunity to access the database directly in C # to see if it will error!
--also want to be involved in the discussion of children's shoes.
--==============================================
PostgreSQL stored procedures dynamically update data