pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHelp on some SQL command...
3+ messages / 3 participants
[nested] [flat]
* Help on some SQL command...
@ 2000-08-16 08:11 Ang Sei Heng <joanna@leopard.cybersource.com.sg>
0 siblings, 1 reply; 3+ messages in thread
From: Ang Sei Heng @ 2000-08-16 08:11 UTC (permalink / raw)
To: pgsql-sql
Hello to all the SQL gurus...
I have this little table:
test1 (
id char(8) primary key,
name char(20),
create_date timestamp
);
Now, the create_date need to be updated
to date and time whenever id is being
inserted or updated.
Is there a way in SQL that I can do this
automatically?
I try the following command using 'trigger'
----
CREATE_TRIGGER test1_autodate
AFTER INSERT OR UPDATE ON
test1 FOR EACH ROW EXECUTE update("test1")
CREATE FUNCTION update(char *) RETURNS int4
AS 'UPDATE $1 set date="now"'
LANGUAGE 'sql';
----
But realized 'char *' is not allow... Is there a
way to solve this?
Or Am I the right track in solving this problem?
Hope someone can help me... thanks.
Sei Heng
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Help on some SQL command...
@ 2000-08-17 08:59 Guo Bin <guobin_@yahoo.com>
0 siblings, 0 replies; 3+ messages in thread
From: Guo Bin @ 2000-08-17 08:59 UTC (permalink / raw)
To: Ang Sei Heng <joanna@leopard.cybersource.com.sg>; pgsql-sql
Hi,
You can specify a default value for the create_date
column like:
create_date timestamp default 'now'
In the insert statement just ommit that field and you
will get the default, as
insert into test1 (id, name) values (1, 'xxx');
Regards,
--
Guo Bin
--- Ang Sei Heng <joanna@leopard.cybersource.com.sg> wrote:
> Hello to all the SQL gurus...
>
> I have this little table:
>
> test1 (
> id char(8) primary key,
> name char(20),
> create_date timestamp
> );
>
> Now, the create_date need to be updated
> to date and time whenever id is being
> inserted or updated.
>
> Is there a way in SQL that I can do this
> automatically?
__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Help on some SQL command...
@ 2000-08-17 12:44 Jesus Aneiros <aneiros@jagua.cfg.sld.cu>
parent: Ang Sei Heng <joanna@leopard.cybersource.com.sg>
0 siblings, 0 replies; 3+ messages in thread
From: Jesus Aneiros @ 2000-08-17 12:44 UTC (permalink / raw)
To: Ang Sei Heng <joanna@leopard.cybersource.com.sg>; +Cc: pgsql-sql
Use default now()
--
Jesus Aneiros Sosa
mailto:aneiros@jagua.cfg.sld.cu
http://jagua.cfg.sld.cu/~aneiros
On Wed, 16 Aug 2000, Ang Sei Heng wrote:
> Hello to all the SQL gurus...
>
> I have this little table:
>
> test1 (
> id char(8) primary key,
> name char(20),
> create_date timestamp
> );
>
> Now, the create_date need to be updated
> to date and time whenever id is being
> inserted or updated.
>
> Is there a way in SQL that I can do this
> automatically?
>
> I try the following command using 'trigger'
>
> ----
> CREATE_TRIGGER test1_autodate
> AFTER INSERT OR UPDATE ON
> test1 FOR EACH ROW EXECUTE update("test1")
>
> CREATE FUNCTION update(char *) RETURNS int4
> AS 'UPDATE $1 set date="now"'
> LANGUAGE 'sql';
> ----
>
> But realized 'char *' is not allow... Is there a
> way to solve this?
>
> Or Am I the right track in solving this problem?
>
> Hope someone can help me... thanks.
>
> Sei Heng
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2000-08-17 12:44 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-08-16 08:11 Help on some SQL command... Ang Sei Heng <joanna@leopard.cybersource.com.sg>
2000-08-17 12:44 ` Jesus Aneiros <aneiros@jagua.cfg.sld.cu>
2000-08-17 08:59 Re: Help on some SQL command... Guo Bin <guobin_@yahoo.com>
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