Search Postgresql Archives

Re: PgSQL not recognized

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

 



am  Mon, dem 13.11.2006, um 15:08:18 -0800 mailte whytwelve13@xxxxxxxxx folgendes:
> I just installed a fresh Postgres database. select version(); gives:
> 
> "PostgreSQL 8.1.5 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC)
> 3.4.2 (mingw-special)"
> 
> Normal statements like select * from sometable work fine.
> 
> I initiated the default databases, created the postgres user and I
> tried to run the following query:
> 
> if 1 <> 1 then
>    select 1
> else
>    select 2
> end if;
> 
> The error was:
> 
> ERROR:  syntax error at or near "if" at character 1
> 
> I added the language using 'createlang plpgsql', but this didn't help.
> This is similar to what I read from
> 
> http://www.postgresql.org/docs/8.1/interactive/plpgsql-control-structures.html
> 
> I tried using the functions:
> 
> create function izitest() returns void as
> 'if 1 <> 1 then
>    select 1
> else
>    select 2
> end if;' language 'plpgsql'
> 
> where plpgsql is the name of the language I created. This gave the same
> error:

There are somethink wrong:

- wrong begin (i use the dollar-quoting-style)
- no 'begin'
- missing ';'
- you want to get a result but defined the function as void


I have rewritten this for you, i hope, this is what you expected:


create function izitest() returns int as $$
begin
if 1 <> 1 then
   return 1;
else
   return 2;
end if;
end;
$$ language 'plpgsql';


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47215,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net


[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