Search Postgresql Archives

Re: Function returning subset of columns from table (return type)

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

 



On Feb 3, 2008 3:23 PM, brian <brian@xxxxxxxxxxxxxxxx> wrote:
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_row
      to_char(added, 'Mon D YYYY'),
      to_char(updated, 'Mon D YYYY'),
      text_col
    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

[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