Re: Function returning subset of columns from table (return type)
От | Gurjeet Singh |
---|---|
Тема | Re: Function returning subset of columns from table (return type) |
Дата | |
Msg-id | 65937bea0802031637n2887319jc1e4ca159e61ad0@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Function returning subset of columns from table (return type) (brian <brian@zijn-digital.com>) |
Ответы |
Re: Function returning subset of columns from table (return
type)
|
Список | pgsql-general |
On Feb 3, 2008 3:23 PM, brian <brian@zijn-digital.com> wrote:
All's okay, except you should not have declared it IMMUTABLE, because the results depend on a database query.
From the docs:
IMMUTABLE indicates that the function cannot modify the database and always returns the same result when given the same argument values; that is, it does not do database lookups or otherwise use information not directly present in its argument list
Best regards,
--
gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com
EnterpriseDB http://www.enterprisedb.com
17° 29' 34.37"N, 78° 30' 59.76"E - Hyderabad
18° 32' 57.25"N, 73° 56' 25.42"E - Pune
37° 47' 19.72"N, 122° 24' 1.69" W - San Francisco *
http://gurjeet.frihost.net
Mail sent from my BlackLaptop device
CREATE TYPE your_type
AS (
added CHAR(11) NOT NULL,
updated CHAR(11) NOT NULL,
text_col TEXT
);
CREATE FUNCTION get_note(id INT)
RETURNS SETOF your_type IMMUTABLE
AS $$
DECLARE
your_row your_type%rowtype;
BEGIN
SELECT INTO your_rowto_char(added, 'Mon D YYYY'),text_col
to_char(updated, 'Mon D YYYY'),
FROM note
WHERE id = $1;
RETURN your_row;
END;
$$ LANGUAGE sql;
All's okay, except you should not have declared it IMMUTABLE, because the results depend on a database query.
From the docs:
IMMUTABLE indicates that the function cannot modify the database and always returns the same result when given the same argument values; that is, it does not do database lookups or otherwise use information not directly present in its argument list
Best regards,
--
gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com
EnterpriseDB http://www.enterprisedb.com
17° 29' 34.37"N, 78° 30' 59.76"E - Hyderabad
18° 32' 57.25"N, 73° 56' 25.42"E - Pune
37° 47' 19.72"N, 122° 24' 1.69" W - San Francisco *
http://gurjeet.frihost.net
Mail sent from my BlackLaptop device
В списке pgsql-general по дате отправления: