pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedproblem with insertion of serial id
2+ messages / 2 participants
[nested] [flat]
* problem with insertion of serial id
@ 2002-08-10 17:42 Michael Zouroudis <mzouroudis@idealcorp.com>
0 siblings, 1 reply; 2+ messages in thread
From: Michael Zouroudis @ 2002-08-10 17:42 UTC (permalink / raw)
To: pgsql-admin
i've been stuck on a problem and i'm hoping that someone out there can
help me out. my problem deals with three tables and one sequence. here
are some example tables
create table mom (
mom_id serial primary key
);
create table dad (
dad_id serial primary key
);
create table mom_dad(
mom_id integer referenced from mom.mom_id
dad_id integer referenced from dad.dad_id
);
a trigger on mom sets off a function that inserts any relevent
information into dad(my real tables obviously have more columns). my
problem occurs when i try to put another trigger on dad that calls a
function that inserts the id's of both tables into mom_dad. my function
looks like this;
create function parents() returns opaque as '
declare
m mom%ROWTYPE;
d dad%ROWTYPE;
md mom_dad%ROWTYPE;
mom_mom_id_seq%ROWTYPE;
d_id integer;
m_id integer;
begin
d_id := new.d_id;
insert into mom_dad(m_id, d_id) values (currval('mom_mom_id_seq'), d_id);
return null;
end;
'language 'plpgsql';
create trigger family after insert or update on dad
for each row execute procedure parents();
when i run this i get a parse error at or near "assets_asset_id_seq". i have also tried make a variable to represent the currval by using a select into statement, but couldn't get it to work. when i put a raise notice statement in the function and manually assign a value to m_id, it returns that value. otherwise, i do not know how to return the correct value(currval of m_id). i have looked at all docs on sequences and have not found an example that works correctly. i must be missing something. if anyone can help me out or point me in the right direction i would greatly appreicate it.
thanks in advance,
mikez
--
Mike Z
Intern
__________________________________________________
I.D.E.A.L. Technology Corporation - Orlando Office
http://www.idealcorp.com - 407.999.9870 x14
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: problem with insertion of serial id
@ 2002-08-10 18:42 Tom Lane <tgl@sss.pgh.pa.us>
parent: Michael Zouroudis <mzouroudis@idealcorp.com>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2002-08-10 18:42 UTC (permalink / raw)
To: Michael Zouroudis <mzouroudis@idealcorp.com>; +Cc: pgsql-admin
Michael Zouroudis <mzouroudis@idealcorp.com> writes:
> when i run this i get a parse error at or near "assets_asset_id_seq".
You need to double those quote marks, viz
... currval(''mom_mom_id_seq'') ...
Or you can backslash 'em (\'). The point is that the function body
begins life as a string literal, and so you have to get it through the
string-literal parser.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-08-10 18:42 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-08-10 17:42 problem with insertion of serial id Michael Zouroudis <mzouroudis@idealcorp.com>
2002-08-10 18:42 ` Tom Lane <tgl@sss.pgh.pa.us>
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