Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

RE: [PostgreSQL-Brasil] STORED PROCEDURES - TRIGGERS: msg#00191

db.postgresql.brasil.user

Subject: RE: [PostgreSQL-Brasil] STORED PROCEDURES - TRIGGERS

pq vc naum usa uma tabela só, e depois extrai os dados da tabela tbl_dataliner com um
"select group by" vc ja tentou ?

From: "Paulo Rogerio Zimolo" <paulorz@xxxxxxxxxxxx>
Reply-To: paulorz@xxxxxxxxxxxx, brasil-usuarios@xxxxxxxxxxxxx
To: <brasil-usuarios@xxxxxxxxxxxxx>
Subject: [PostgreSQL-Brasil] STORED PROCEDURES - TRIGGERS
Date: Fri, 27 Jan 2006 16:36:23 -0200

Senhores,
Tenho duas tabelas, tbl_dataliner e tbl_dataliner_total, sendo que a segunda
consiste em um agrupamento de alguns dados da primeira.
Como semanalmente tenho que inserir dados na tbl_dataliner (aprox 30000
registros), criei as triggers abaixo para que depois de inserir os dados na
tbl_dataliner, os dados da tbl_dataliner_total sejam deletados, para que em
seguida seja refeito o agrupamento dos dados da tabela tbl_dataliner para a
tabela tbl_dataliner _total (ja incluindo os novos dados).
Ocorre que as funcoes nao estao funcionando corretamente.
Nao sei se estou fazendo do jeito certo, portanto se alguem conhecer alguma
forma de fazer com que a funcao seja chamada apenas uma vez (pelo select) e
nao por cada entrada, ou mesmo se puder dizer onde estou errando, eu
agradeceria muito.
Atenciosamente
Paulo

1) create trigger exc_dataliner_total after insert on tbl_dataliner for
each statement execute procedure fexc_dataliner_total();

2) CREATE OR REPLACE FUNCTION fexc_dataliner_total() returns trigger as
'
BEGIN

DELETE from tbl_dataliner_total;
RETURN OLD;

END;
'
LANGUAGE 'PLPGSQL';



3)create trigger ins_dataliner_total after delete on tbl_dataliner_total
for each statement execute procedure fins_dataliner_total();



4)CREATE OR REPLACE FUNCTION fins_dataliner_total() returns trigger as
'
DECLARE
reg RECORD;

BEGIN
if tg_op = ''INSERT'' then
FOR reg IN SELECT fk_lporto, fk_cliente, fk_carrier, commodity,
fk_odporto, fk_direction, fk_month, year, SUM(teu)::INT AS teu FROM
tbl_dataliner GROUP BY fk_lporto, fk_cliente, fk_carrier, commodity,
fk_odporto, fk_direction, fk_month, year

LOOP

INSERT INTO tbl_dataliner_total (fk_lporto, fk_cliente, fk_carrier,
commodity, fk_odporto, fk_direction, fk_month, year, teu)

VALUES (reg.fk_lporto, reg.fk_cliente, reg.fk_carrier, reg.commodity,
reg.fk_odporto, reg.fk_direction, reg.fk_month, reg.year, reg.teu);

END LOOP;
END if;
return reg;
END;
'
LANGUAGE 'PLPGSQL';




_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
http://www.postgresql.org.br

_________________________________________________________________
Ligações gratuitas de PC-para-PC para qualquer lugar do Brasil e do mundo com o MSN Messenger. Saiba mais em http://imagine-msn.com/messenger/default2.aspx?locale=pt-br

_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
http://www.postgresql.org.br



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
ide.eclipse.wtp...    bug-tracking.ro...    xfree86.cvs/200...    lisp.wxcl.devel...    file-systems.ar...    kde.devel.kwrit...    jakarta.jetspee...    qnx.openqnx.dev...    drivers.openib/...    ports.xbox.deve...    gis.gdal.devel/...    netbsd.ports.ma...    ubuntu.marketin...    systemtap/2005-...    web.omniweb/200...    mail.qmail.ldap...    hardware.soekri...    os.netbsd.devel...    audio.madman.ge...    tv.freeguide-tv...    cluster.openmos...    education.ezpro...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation