From: Najm Hashmi <najm@mondo-live.com>
To: Edmar Wiggers <edmar@brasmap.com>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: INSERT [IGNORE] INTO TABLE
Date: Wed, 01 Nov 2000 12:56:26 -0500
Message-ID: <3A00594A.AA3A3120@mondo-live.com> (raw)
References: <NEBBIAKDCDHFGJMLHCKIOEMNCAAA.edmar@brasmap.com>
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
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-sql@postgresql.org
Cc: najm@mondo-live.com, edmar@brasmap.com
Subject: Re: INSERT [IGNORE] INTO TABLE
In-Reply-To: <3A00594A.AA3A3120@mondo-live.com>
References: <NEBBIAKDCDHFGJMLHCKIOEMNCAAA.edmar@brasmap.com> <3A00594A.AA3A3120@mondo-live.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