Unix Technical Forum

Re: a how can I do this in Informix question

This is a discussion on Re: a how can I do this in Informix question within the Informix forums, part of the Database Server Software category; --> Hi. I know a method, but maybe it's not very elegant. You can use on a trigger an "execute ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 10:28 AM
=?iso-8859-1?Q?Omar_Mu=F1oz_Perez?=
 
Posts: n/a
Default Re: a how can I do this in Informix question


Hi.

I know a method, but maybe it's not very elegant.

You can use on a trigger an "execute function" and get returned
value into a column of the table.

Here you have a little example. My goal is enforce "value2" on table
to take the same value of "value1" on insert.

--## My prove-table
create table tmpomar (valor1 date, valor2 date);

--## A function which returns teh same.. sorry, I don't know a better way
create function sp_dummyomar (pD_Valor date)
returning date;
return pD_Valor;
end function;

--## My trigger using my enforcing function
create trigger trgomar insert on tmpomar
referencing new as n
for each row
(
execute function sp_dummyomar(n.valor1) into valor2
);

-- ## Finally, when I execute this (today here is October 26th) ...
insert into tmpomar values (today-2, today);
insert into tmpomar values (today-4, today);
insert into tmpomar values (today-8, today);

--## I get this:
select * from tmpomar;

valor1 valor2
10/26/2005 10/26/2005
10/24/2005 10/24/2005
10/20/2005 10/20/2005

This can be done with update triggers also (beware with modify same
columns than triggering-columns)

So, If you create a function playing with CURRENT - YEAR - MONTH-
DAY functions as Martin said, you will have the behaviour you are looking
for.

By the way, I'm using IDS 9.30.UC6. More info at "Informix Guide to
SQL: Syntax" page 2-316 and so on.

Later

Omar Muqoz

----- Original Message -----
From: "Quetzalcoatl" <quetzalcoatl@pandora.be>
To: <informix-list@iiug.org>
Sent: Thursday, October 27, 2005 1:35 PM
Subject: a how can I do this in Informix question


> Hello,
>
> I have a problem in Informix that I need to solve.
>
> I have table
>
> Table ABC
> {
> Field1 integer,
> Field2 char(5),
> Insdate integer
> }
>
> What I want now is when an insert occurs on this table on the fields
> (Field1 and Field2) that afterwards the fields Insdate is filled with
> the date of today but stored as a number in the format YYYYMMDD.
>
> Example:
>
> Insert into ABC (Field1, Field2)
> values (1, "Wim");
>
> then should the query
>
> Select * from ABC;
>
> return:
>
> Field1 Field2 Insdate
> 1 Wim 20051027
>
> My collegue found how to do it in Oracle and now I want to prove it also
> can be done in Informix. I hope. Else me and my big mouth :-)
>
> So help me please.
>
> Thanks,
>
> Wim

sending to informix-list
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:54 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com