Обсуждение: Create Function (SQL)

Поиск
Список
Период
Сортировка

Create Function (SQL)

От
Mark Simon
Дата:
I am trying to create a simple function using SQL rather than PGSQL. At this point, it's just for the exercise.

Is it possible to create a function similar to the following:

    create function thing(text) as select * from whatever where id=$1;

Do I need to specify all of the columns from the table (whatever) as out parameters, or as a return type, or can I have a generic table returned from this?

Thanks,

Mark
--
#signature { color: #00008B; font-family: sans-serif; font-size: 10pt;}#signature h1 { font-size: 125%; margin: 4px 0px;}#signature p { margin: 4px 0px;}#signature a { color: #005247; text-decoration: none;}

Mark Simon

Manngo Net Pty Ltd

Phone/Fax: 1300 726 000
mobile: 0411 246 672

email: mark@manngo.net
web: http://www.manngo.net

Resume: http://mark.manngo.net

Re: Create Function (SQL)

От
imad
Дата:
You can return a record:

create function thing(text) returns record as 'select * from whatever
where id=$1' language sql;

Hope this helps.

--Imad
www.EnterpriseDB.com



On 11/5/06, Mark Simon <mark@manngo.net> wrote:
>
>  I am trying to create a simple function using SQL rather than PGSQL. At
> this point, it's just for the exercise.
>
>  Is it possible to create a function similar to the following:
>
>      create function thing(text) as select * from whatever where id=$1;
>
>  Do I need to specify all of the columns from the table (whatever) as out
> parameters, or as a return type, or can I have a generic table returned from
> this?
>
>  Thanks,
>
>  Mark
>
> --
>
>
> Mark Simon
>
> Manngo Net Pty Ltd
>
> Phone/Fax: 1300 726 000
>  mobile: 0411 246 672
>
> email: mark@manngo.net
>  web: http://www.manngo.net
>
> Resume: http://mark.manngo.net