Search Postgresql Archives

Re: Implementing replace function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



\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


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux