Inser/update

Honza Pazdziora adelton na fi.muni.cz
Úterý Leden 25 14:00:08 CET 2005


On Tue, Jan 25, 2005 at 01:51:29PM +0100, "Petr \"Qaxi\" Klíma" wrote:
> >
> >Tak udelejte 
> >
> >	insert into passwd select ( ..... ) from dual
> >	where not exists ( select 1 from passwd where username = ... )]
> >
> tohle mi ale neosetri "nove" uzivatel (UPDATE)... ,ze?

Tohle Vam prave zalozi nove uzivatele. V prvnim pruchodu (nebo druhem,
to je jedno) udelate update existujicich. A muzete si v tom shellu i
zkontrolovat, ktere updaty prosly (a tudiz uz se nema delat insert) a
ktere ne (a je potreba uzivatele zalozit).

> >tohle mi ale neosetri "nove" uzivatel ... ,ze
> >
> >nebo where uid = ... . Pripadne to obalit begin a end a zachytnout
> >vyjimku, kterou Vam server vrati.
>
> to bych to ale asi musel zaregistrovat jako proceduru ...., ze
> tohle mi nechodi ...
> 
> #ERROR:  parser: parse error at or near "select" at character 12
> 
> begin
>    select * from passwd where uid='2011' AND username='benes';
>    if not exist
>    then
>        insert into passwd ( uid, username ) VALUES ('2011','benes');
>    else
>        update passwd set uid='2011', username='benes' ;
>    endif
> end
> #(Duration 0:00.10)
> 
> SORRY
> 
> ja myslel (vim, ze se to nema delat ...), ze kdyz mam nejake zkusenosti 
> s MySQL tak budu schopen PSQL pouzivat hned a .....

Jste mel rict hned, ze pouzivate PostgreSQL -- ten bohuzel rozumnou
podporu vyjimek nema.

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton na fi.muni.cz | http://www.fi.muni.cz/~adelton/
 .project: Perl, mod_perl, DBI, Oracle, large Web systems, XML/XSL, ...
		Only self-confident people can be simple.


Další informace o konferenci Databases