pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedsorry, now with subject... trigger & nextval(seq)
4+ messages / 3 participants
[nested] [flat]
* sorry, now with subject... trigger & nextval(seq)
@ 2010-05-21 00:53 tlange@gwdg.de
2010-05-21 01:46 ` Re: sorry, now with subject... trigger & nextval(seq) Adrian Klaver <adrian.klaver@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: tlange@gwdg.de @ 2010-05-21 00:53 UTC (permalink / raw)
To: pgsql-sql
Hello all,
I'm new to triggers in PostgreSQL. I have to create a trigger on insert to
increment a sequence to overcome MS-Access' limitation in acknowledging
serial "datatype".
Could anyone put me on right track? I was looking the whole day for
references on that... Years ago I quickly found a reference how to do it
in Oracle. However, I could not find anything that explained how to do
this in postgresql... I think, it should go the direction see below... But
how exactly :-/ ?
Many thanks for any help, Torsten
create table testtab (
pid bigint,
sometext text
);
create sequence test;
-- hmm something like this...?
CREATE FUNCTION count_up (varchar) RETURNS opaque AS '
DECLARE
pid_num bigint;
BEGIN
select into pid_num from select nextval($);
RETURN pid_num;
END;
' LANGUAGE 'plpgsql';
-- and how will the trigger looks like
???
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: sorry, now with subject... trigger & nextval(seq)
2010-05-21 00:53 sorry, now with subject... trigger & nextval(seq) tlange@gwdg.de
@ 2010-05-21 01:46 ` Adrian Klaver <adrian.klaver@gmail.com>
2010-06-01 11:05 ` Re: sorry, now with subject... trigger & nextval(seq) Daniel Migowski <dmigowski@ikoffice.de>
0 siblings, 1 reply; 4+ messages in thread
From: Adrian Klaver @ 2010-05-21 01:46 UTC (permalink / raw)
To: pgsql-sql
On Thursday 20 May 2010 5:53:51 pm tlange@gwdg.de wrote:
> Hello all,
>
> I'm new to triggers in PostgreSQL. I have to create a trigger on insert to
> increment a sequence to overcome MS-Access' limitation in acknowledging
> serial "datatype".
>
> Could anyone put me on right track? I was looking the whole day for
> references on that... Years ago I quickly found a reference how to do it
> in Oracle. However, I could not find anything that explained how to do
> this in postgresql... I think, it should go the direction see below... But
> how exactly :-/ ?
>
>
> Many thanks for any help, Torsten
>
>
> create table testtab (
> pid bigint,
> sometext text
> );
>
> create sequence test;
>
> -- hmm something like this...?
> CREATE FUNCTION count_up (varchar) RETURNS opaque AS '
> DECLARE
> pid_num bigint;
> BEGIN
> select into pid_num from select nextval($);
> RETURN pid_num;
> END;
> ' LANGUAGE 'plpgsql';
>
> -- and how will the trigger looks like
> ???
You know serial is just a shortcut for:
pid int NOT NULL DEFAULT nextval('seq')
I think you will find Access will place nice if you use the long form to define
your autoincrement.
--
Adrian Klaver
adrian.klaver@gmail.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: sorry, now with subject... trigger & nextval(seq)
2010-05-21 00:53 sorry, now with subject... trigger & nextval(seq) tlange@gwdg.de
2010-05-21 01:46 ` Re: sorry, now with subject... trigger & nextval(seq) Adrian Klaver <adrian.klaver@gmail.com>
@ 2010-06-01 11:05 ` Daniel Migowski <dmigowski@ikoffice.de>
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Migowski @ 2010-06-01 11:05 UTC (permalink / raw)
To: pgsql-sql
Am 21.05.2010 03:46, schrieb Adrian Klaver:
> You know serial is just a shortcut for:
>
> pid int NOT NULL DEFAULT nextval('seq')
>
> I think you will find Access will place nice if you use the long form to define
> your autoincrement.
>
Not true. Serial will also add an internal dependency between the
sequence, will create the sequence and will drop everything if the
column gets dropped.
Regards,
Daniel Migowski
Attachments:
dmigowski.vcf (text/x-vcard, 293B) download
begin:vcard
fn:Daniel Migowski
n:Migowski;Daniel
org:IKOffice.de
adr:;;Nordstr. 10;Oldenburg;Niedersachen;26123;Deutschland
email;internet:dmigowski@ikoffice.de
title:Dipl.-Inf.
tel;work:0441-2198895-2
tel;fax:0441-2198895-5
x-mozilla-html:TRUE
url:http://www.ikoffice.de
version:2.1
end:vcard
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: sorry, now with subject... trigger & nextval(seq)
@ 2010-05-21 07:35 tlange@gwdg.de
0 siblings, 0 replies; 4+ messages in thread
From: tlange@gwdg.de @ 2010-05-21 07:35 UTC (permalink / raw)
To: pgsql-sql
> On Thu, May 20, 2010 at 5:52 PM, <tlange@gwdg.de> wrote:
>
>> I'm new to triggers in PostgreSQL. I have to create a trigger on insert
>> to
>> increment a sequence to overcome MS-Access' limitation in acknowledging
>> serial "datatype".
>
> Uh? Access doesn't need to acknowledge the serial datatype.
> At-least in recent versions auto increment is recognized by MS-Access
> just fine (I'm guessing this is due to the Return clause which the
> ODBC driver automatically calls).
>
Thanks Richard. Ok, I hope our Access version is not too old (97 or 2000 I
think) because I could not insert. I'll try the most recent ODBC driver
and follow also Adrians suggestion.
Torsten
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2010-06-01 11:05 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-05-21 00:53 sorry, now with subject... trigger & nextval(seq) tlange@gwdg.de
2010-05-21 01:46 ` Adrian Klaver <adrian.klaver@gmail.com>
2010-06-01 11:05 ` Daniel Migowski <dmigowski@ikoffice.de>
2010-05-21 07:35 Re: sorry, now with subject... trigger & nextval(seq) tlange@gwdg.de
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