Re: Porting from MSSQL Server

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Porting from MSSQL Server
Дата
Msg-id 20030824093312.O58583-100000@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Porting from MSSQL Server  ("Hans Jorgensen" <jorgensenhans@hotmail.com>)
Список pgsql-novice
On Sun, 24 Aug 2003, Hans Jorgensen wrote:

> I am porting a database from M$SQL Server to PostgreSQL.
>
> I have a problem with a query. On MS SQL Server it looks like this:
>
> DECLARE @handle AS NVARCHAR(40)
> EXEC @handle = IPAddressToHandle 'x.x.x.x'
> SELECT * FROM tblEmployee WHERE tblEmployee.handle = @handle UNION SELECT
> ...
>
> I have created the function  IPAddressToHandle which works, but how do I
> declare the variable handle, execute the function and then the query with
> the variable as parameter.

I think you'll need to write an appropriate function (unless you're doing
this from psql).  If you want the output from the select (as opposed to
doing something else with it, it might be as simple as something like:

CREATE OR REPLACE FUNCTION foo(text) returns setof tblEmployee as '
DECLARE
 handlevar varchar(40);
 r record;
BEGIN
 handlevar := IPAddressToHandle($1);
 FOR r IN SELECT * from tblEmployee where handle=handlevar
  UNION ...
   RETURN NEXT r;
 END LOOP;
 RETURN;
END;' language 'plpgsql';

select * from foo('x.x.x.x');



В списке pgsql-novice по дате отправления:

Предыдущее
От: Michael Guerin
Дата:
Сообщение: Cursors
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: Cursors