Re: Implementing replace function - Mailing list pgsql-general

From Alexander Farber
Subject Re: Implementing replace function
Date
Msg-id AANLkTikt9NROCRxXRYhefbhXuStJpFNHXsXP+VcST45G@mail.gmail.com
Whole thread Raw
In response to Re: Implementing replace function  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: Implementing replace function
Re: Implementing replace function
List pgsql-general
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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: NOT IN (NULL) ?
Next
From: Rob Sargent
Date:
Subject: Re: Implementing replace function