From: | Rob Sargent <robjsargent(at)gmail(dot)com> |
---|---|
To: | Alexander Farber <alexander(dot)farber(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Implementing replace function |
Date: | 2010-10-31 17:34:49 |
Message-ID: | 4CCDA8B9.6070208@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
\df *update*
Alexander Farber wrote:
> I've created a function now (below) and can call it as well,
> but how can I see it at the psql prompt? Is there a \d command
> for that or should I dump the database to see my declarations?
>
> And is my function atomic? I.e. can't it happen, that FOUND
> is not true, but then another session calls a INSERT inbetween?
>
> pref=> create or replace function pref_update_users(_id varchar,
> pref(> _first_name varchar, _last_name varchar, _female boolean,
> pref(> _avatar varchar, _city varchar, _last_ip inet)
> returns void as $BODY$
> pref$> BEGIN
> pref$>
> pref$> update pref_users set
> pref$> first_name = _first_name,
> pref$> last_name = _last_name,
> pref$> female = _female,
> pref$> avatar = _avatar,
> pref$> city = _city,
> pref$> last_ip = _last_ip
> pref$> where id = _id;
> pref$>
> pref$> IF NOT FOUND THEN
> pref$> insert into pref_users(id, first_name,
> pref$> last_name, female, avatar, city, last_ip)
> pref$> values (_id, _first_name, _last_name,
> pref$> _female, _avatar, _city, _last_ip);
> pref$> END IF;
> pref$> END;
> pref$> $BODY$ language plpgsql;
> CREATE FUNCTION
>
> Thanks and merry Halloween
> Alex
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Raymond O'Donnell | 2010-10-31 17:39:17 | Re: Implementing replace function |
Previous Message | Alexander Farber | 2010-10-31 17:28:56 | Re: Implementing replace function |