simply want to swap all column value we can achieve by,
1) renaming column
2) by creating one more temporary column
if we like to swap column say fname and lname to be swapped by condition on id > 300 on table personal
CREATE OR REPLACE FUNCTION swap() RETURNS integer
AS
$BODY$
DECLARE
-- declare anyvariable over here
VFname varchar;
VLasswd varchar ;
VSwap personal%rowtype;
-- create cursor
CSwap cursor for select id,fname,lname from personal where id > 300;
BEGIN
open CSwap;
loop fetch next from CSwap into VSwap;
exit when not found;
raise notice 'fname : % , lname : %',VSwap.fname,VSwap.lname;
update personal set fname=VSwap.lname,lname=VSwap.fname where id = VSwap.id;
end loop;
RETURN 1;
END;
$BODY$
LANGUAGE 'plpgsql'
call the function by
select swap();
explain : cursor CSwap hold the value of fname, lanme and id greater then 300
when looping cursor just updating fname and lanme using cursor variable VSwap.lanme and VSwap.fname by matching id with VSwap.id
All about data processing & analytics. Open source database,No-SQL and Hadoop. Discussed issues/solution which I've got during my experience..
Wednesday, May 11, 2011
Subscribe to:
Posts (Atom)
Labels
- #agriculture (1)
- #ai (5)
- #pdf (1)
- Big Data (30)
- blogging (3)
- data analytics (5)
- data science (7)
- Deep Learning (4)
- Hadoop (28)
- Hadoop Eco System (27)
- hdfsCommands (4)
- Hive (5)
- IssueSolution (4)
- jobs (3)
- links (1)
- Machine Learning (4)
- mahout (2)
- MapReduce (1)
- MongoDB (6)
- MySQL (4)
- PlpgSQL (8)
- postgres (6)
- PostgreSQL (53)
- R (20)
- RHadoop (2)
- search keywords (1)
- social (2)
- spark (3)
- twitter (6)
- usecase (2)
- visualization (7)
- weka (1)