pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Zouroudis <mzouroudis@idealcorp.com>
To: pgsql-admin@postgresql.org
Subject: problem with insertion of serial id
Date: Sat, 10 Aug 2002 13:42:27 -0400
Message-ID: <3D555083.9040402@idealcorp.com> (raw)

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





view thread (2+ messages)  latest in thread

Message-ID: <3D555083.9040402@idealcorp.com>
Permalink:  ../3D555083.9040402@idealcorp.com/
Also on:    postgresql.org/message-id/3D555083.9040402@idealcorp.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mzouroudis@idealcorp.com
  Subject: Re: problem with insertion of serial id
  In-Reply-To: <3D555083.9040402@idealcorp.com>
  References: <3D555083.9040402@idealcorp.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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