Received: from lin.local.lan ([216.221.221.2]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id e9VHsGl87217 for ; Tue, 31 Oct 2000 12:54:16 -0500 (EST) (envelope-from najm@mondo-live.com) Received: from mondo-live.com (IDENT:najm@ll51.local2.lan [192.168.2.51]) by lin.local.lan (8.9.3/8.8.7) with ESMTP id PAA15036; Tue, 31 Oct 2000 15:12:33 GMT Message-ID: <3A00594A.AA3A3120@mondo-live.com> Date: Wed, 01 Nov 2000 12:56:26 -0500 From: Najm Hashmi X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-5.0BOOT i686) X-Accept-Language: en MIME-Version: 1.0 To: Edmar Wiggers , "pgsql-sql@postgresql.org" Subject: Re: INSERT [IGNORE] INTO TABLE References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200010/28 X-Sequence-Number: 28 Edmar Wiggers wrote: > > If I try to insert some row which in the table already exist the > > postgre don't insert it and tell some error. Everything ok. > > I'll insert only if there is not the same (same key) record, > > else don't insert and don't tell me errors about it. > > In MySQL is a switch [IGNORE]. > > Not a good feature for me. What do you do if the record already exists? > Update it? > > Check existence and then insert or update. If you want, I guess you could > wrap that inside a stored procedure. Hi, here is an example of using function using pl/pgsql for inserting and checking whether an instance exists or not..... CREATE FUNCTION add_new_user(text,text) RETURNS bool AS' DECLARE oldUser RECORD; USR ALIAS FOR $1; PWORD ALIAS FOR $2; BEGIN SELECT INTO oldUser * FROM users where username=USR AND password= PWORD; IF FOUND THEN RETURN ''f''; ELSE INSERT INTO USERS(username,password) values(USR,PWORD); RETURN ''t''; END IF; END;' LANGUAGE 'plpgsql'; Regards. Najm