Harald Armin Massa wrote:
I have a table:
CREATE TABLE rechner
(
  id_r int4 NOT NULL DEFAULT nextval('rechner_id_r_seq'::regclass),
  name text,
  CONSTRAINT rechner_pkey PRIMARY KEY (id_r)
)
CREATE UNIQUE INDEX rechner_name
  ON rechner
  USING btree
  (name);

and want to have the existing or new id of 'newobjekt'
CREATE OR REPLACE FUNCTION getrechnerid( text)
  RETURNS int4 AS
'        DECLARE
            result int4;
        BEGIN
            select id_r from rechner where name=upper($1) into result;
IF not FOUND THEN
       select nextval(''swcheck_id_check_seq'') into result;
       insert into rechner (id_r, name) values (result, upper($1));

Why don't you just use the default? You could entirely do away with the 'result' variable that way:

CREATE OR REPLACE FUNCTION getrechnerid( text)
  RETURNS int4 AS
'   BEGIN
      select id_r from rechner where name=upper($1) into result;

      IF not FOUND THEN
         insert into rechner (name) values (upper($1));
      END IF;
...


--
Alban Hertroys
[EMAIL PROTECTED]

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
   7500 AK Enschede

//Showing your Vision to the World//

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to