pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Artimenko Igor <igorart7@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Copy command freezes but INSERT works fine with trigger on insert.
Date: Fri, 27 Aug 2004 13:16:14 -0700 (PDT)
Message-ID: <20040827201614.78627.qmail@web11905.mail.yahoo.com> (raw)

I tried to add up records 2 different ways: 
1.	using command [copy messageinfo (user_id,  receivedtime, filename,  sendersstring, subject,
hasattachments,  groupmsg,  msgsize,  version ) FROM '/meridtemp/messageinfo.dat';] from psql
2.	using simple INSERT INTO messageinfo ( user_id ) VALUES( 1728::int8 );

In 2nd case it worked but not in 1st one. Why? 
Later I did an experiment & repeated it few times. After copy command is running for a while  from
within psql and trying to insert 60,000 records I interrupted it by pressing CTRL+C few times.
Each time I had different line within addmsgcountSync where it stopped. It tells me that “copy”
command does not freeze on one particular statement but it did not insert a single record.

For this table messageinfo I have trigger:
CREATE TRIGGER msgInjector AFTER INSERT ON messageinfo FOR EACH ROW
    EXECUTE PROCEDURE addmsgcountSync();
 
CREATE OR REPLACE FUNCTION addmsgcountSync() RETURNS TRIGGER AS 
'
DECLARE 
 currentTime injector.lastreceivedtime%TYPE;
 vlastreceivedtime injector.lastreceivedtime%TYPE;
 userIdRec RECORD;
 vID messageinfo.user_id%TYPE;
 injectorCursor CURSOR ( tt int8 ) FOR SELECT lastreceivedtime FROM injector WHERE injector.id =
tt::int8 ;

BEGIN
	vID = NEW.user_id;
	IF ( vID IS NOT NULL ) THEN
		-- Find out lastrecievedtime we need cursor
		OPEN injectorCursor( vID );
		FETCH injectorCursor INTO userIdRec;
		vlastreceivedtime = userIdRec.lastreceivedtime;
		CLOSE injectorCursor;
		currentTime = CURRENT_TIMESTAMP;
		IF vlastreceivedtime < currentTime THEN
			vlastreceivedtime = currentTime;
		END IF;
		-- To make sure time of last message is not newer than lastreceivedtime time
		IF vlastreceivedtime < NEW.receivedtime THEN
			vlastreceivedtime = NEW.receivedtime;
		END IF;
		-- Stopes copy command but not insert one ?
		UPDATE injector SET addmsgcount = addmsgcount + 1, lastreceivedtime = vlastreceivedtime WHERE
injector.id = vID::int8;
	END IF;
	RETURN NULL;
END;
'
  LANGUAGE 'plpgsql';



=====
Thanks a lot
Igor Artimenko
I specialize in 
Java, J2EE, Unix, Linux, HP, AIX, Solaris, Progress, Oracle, DB2, Postgres, Data Modeling


	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 



view thread (3+ messages)  latest in thread

Message-ID: <20040827201614.78627.qmail@web11905.mail.yahoo.com>
Permalink:  ../20040827201614.78627.qmail@web11905.mail.yahoo.com/
Also on:    postgresql.org/message-id/20040827201614.78627.qmail@web11905.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: igorart7@yahoo.com
  Subject: Re: Copy command freezes but INSERT works fine with trigger on insert.
  In-Reply-To: <20040827201614.78627.qmail@web11905.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox