pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedInc
9+ messages / 4 participants
[nested] [flat]
* Inc
@ 2007-03-06 16:55 Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Ezequias Rodrigues da Rocha @ 2007-03-06 16:55 UTC (permalink / raw)
To: pgsql-sql
Hi list,
There is any function to increment with 1 some field.
For example. I have a table with a field that on each update it
incrementes a field that is allways configured to 0 before the
starting of updates.
Regards
--
Ezequias Rodrigues da Rocha
http://ezequiasrocha.blogspot.com/
use Mozilla Firefox:http://br.mozdev.org/firefox/
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Inc
@ 2007-03-06 17:13 Richard Huxton <dev@archonet.com>
parent: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Richard Huxton @ 2007-03-06 17:13 UTC (permalink / raw)
To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql
Ezequias Rodrigues da Rocha wrote:
> Hi list,
>
> There is any function to increment with 1 some field.
>
> For example. I have a table with a field that on each update it
> incrementes a field that is allways configured to 0 before the
> starting of updates.
Something like:
CREATE FUNCTION my_autoinc() RETURNS TRIGGER AS $$
BEGIN
NEW.counter := NEW.counter + 1;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER my_counter_trig BEFORE UPDATE ON my_table
FOR EACH ROW EXECUTE PROCEDURE my_autoinc();
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Inc
@ 2007-03-06 17:29 Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
parent: Richard Huxton <dev@archonet.com>
0 siblings, 3 replies; 9+ messages in thread
From: Ezequias Rodrigues da Rocha @ 2007-03-06 17:29 UTC (permalink / raw)
To: Richard Huxton <dev@archonet.com>; +Cc: pgsql-sql
Thank you but I must inc an specific row. How to do that ?
Ezequias
2007/3/6, Richard Huxton <dev@archonet.com>:
> Ezequias Rodrigues da Rocha wrote:
> > Hi list,
> >
> > There is any function to increment with 1 some field.
> >
> > For example. I have a table with a field that on each update it
> > incrementes a field that is allways configured to 0 before the
> > starting of updates.
>
> Something like:
>
> CREATE FUNCTION my_autoinc() RETURNS TRIGGER AS $$
> BEGIN
> NEW.counter := NEW.counter + 1;
> RETURN NEW;
> END;
> $$ LANGUAGE plpgsql;
>
> CREATE TRIGGER my_counter_trig BEFORE UPDATE ON my_table
> FOR EACH ROW EXECUTE PROCEDURE my_autoinc();
>
> --
> Richard Huxton
> Archonet Ltd
>
--
Ezequias Rodrigues da Rocha
http://ezequiasrocha.blogspot.com/
use Mozilla Firefox:http://br.mozdev.org/firefox/
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Inc
@ 2007-03-06 17:40 Richard Broersma Jr <rabroersma@yahoo.com>
parent: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2 siblings, 1 reply; 9+ messages in thread
From: Richard Broersma Jr @ 2007-03-06 17:40 UTC (permalink / raw)
To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql
--- Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com> wrote:
> Thank you but I must inc an specific row. How to do that ?
>
Does,
UPDATE your_table
SET your_row = your_row +1
WHERE your_pkey = <some value>;
not do what you need?
Regards,
Richard Broersma Jr.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Inc
@ 2007-03-06 17:46 Andreas Kretschmer <akretschmer@spamfence.net>
parent: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2 siblings, 0 replies; 9+ messages in thread
From: Andreas Kretschmer @ 2007-03-06 17:46 UTC (permalink / raw)
To: pgsql-sql
Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com> schrieb:
> Thank you but I must inc an specific row. How to do that ?
Read the answer again.
Please, no silly TOFU (german synonym for text above, fullquote below).
> >> For example. I have a table with a field that on each update it
> >> incrementes a field that is allways configured to 0 before the
> >> starting of updates.
> >Something like:
> >CREATE FUNCTION my_autoinc() RETURNS TRIGGER AS $$
> >BEGIN
> > NEW.counter := NEW.counter + 1;
> > RETURN NEW;
> >END;
> >$$ LANGUAGE plpgsql;
> >CREATE TRIGGER my_counter_trig BEFORE UPDATE ON my_table
> >FOR EACH ROW EXECUTE PROCEDURE my_autoinc();
Your task is only to adapt this to your table-design.
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Inc
@ 2007-03-06 17:54 Andreas Kretschmer <akretschmer@spamfence.net>
parent: Richard Broersma Jr <rabroersma@yahoo.com>
0 siblings, 1 reply; 9+ messages in thread
From: Andreas Kretschmer @ 2007-03-06 17:54 UTC (permalink / raw)
To: pgsql-sql
Richard Broersma Jr <rabroersma@yahoo.com> schrieb:
> --- Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com> wrote:
>
> > Thank you but I must inc an specific row. How to do that ?
> >
>
> Does,
>
> UPDATE your_table
> SET your_row = your_row +1
> WHERE your_pkey = <some value>;
>
> not do what you need?
I think, he is searching for a TRIGGER and he has got the solution.
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Inc
@ 2007-03-06 18:02 Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
parent: Andreas Kretschmer <akretschmer@spamfence.net>
0 siblings, 0 replies; 9+ messages in thread
From: Ezequias Rodrigues da Rocha @ 2007-03-06 18:02 UTC (permalink / raw)
To: Andreas Kretschmer <akretschmer@spamfence.net>; +Cc: pgsql-sql
Now that's ok. Thank you all. I just thought that there was a function
to inc an integer field in postgresql.
Best regards
Ezequias
2007/3/6, Andreas Kretschmer <akretschmer@spamfence.net>:
> Richard Broersma Jr <rabroersma@yahoo.com> schrieb:
>
> > --- Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com> wrote:
> >
> > > Thank you but I must inc an specific row. How to do that ?
> > >
> >
> > Does,
> >
> > UPDATE your_table
> > SET your_row = your_row +1
> > WHERE your_pkey = <some value>;
> >
> > not do what you need?
>
> I think, he is searching for a TRIGGER and he has got the solution.
>
>
> Andreas
> --
> Really, I'm not out to destroy Microsoft. That will just be a completely
> unintentional side effect. (Linus Torvalds)
> "If I was god, I would recompile penguin with --enable-fly." (unknow)
> Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Inc
@ 2007-03-06 18:08 Richard Huxton <dev@archonet.com>
parent: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2 siblings, 1 reply; 9+ messages in thread
From: Richard Huxton @ 2007-03-06 18:08 UTC (permalink / raw)
To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql
Ezequias Rodrigues da Rocha wrote:
> Thank you but I must inc an specific row. How to do that ?
I'm not sure I understand. A row in a different table?
...
BEGIN
UPDATE some_table SET counter = counter + 1;
END;
...
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Inc
@ 2007-03-06 19:09 Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
parent: Richard Huxton <dev@archonet.com>
0 siblings, 0 replies; 9+ messages in thread
From: Ezequias Rodrigues da Rocha @ 2007-03-06 19:09 UTC (permalink / raw)
To: Richard Huxton <dev@archonet.com>; +Cc: pgsql-sql
I did like this:
update base.destinationTable set MyCountField = MyCountField + 1 where
id = new.keyField_ID;
I think it works becouse my tests are ok.
My really thank you all.
Ezequias
2007/3/6, Richard Huxton <dev@archonet.com>:
> Ezequias Rodrigues da Rocha wrote:
> > Thank you but I must inc an specific row. How to do that ?
>
> I'm not sure I understand. A row in a different table?
>
> ...
> BEGIN
> UPDATE some_table SET counter = counter + 1;
> END;
> ...
>
> --
> Richard Huxton
> Archonet Ltd
>
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2007-03-06 19:09 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-03-06 16:55 Inc Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2007-03-06 17:13 ` Richard Huxton <dev@archonet.com>
2007-03-06 17:29 ` Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2007-03-06 17:40 ` Richard Broersma Jr <rabroersma@yahoo.com>
2007-03-06 17:54 ` Andreas Kretschmer <akretschmer@spamfence.net>
2007-03-06 18:02 ` Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2007-03-06 17:46 ` Andreas Kretschmer <akretschmer@spamfence.net>
2007-03-06 18:08 ` Richard Huxton <dev@archonet.com>
2007-03-06 19:09 ` Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.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