Re: function volatility

From: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>
To: maps(at)navigator-info(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: function volatility
Date: 2010-11-22 12:08:18
Message-ID: 201011221308.18074.leif@solumslekt.org
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-novice

On Monday 22. November 2010 12.30.31 maps(at)navigator-info(dot)com wrote:
>
> How to declare function that return set of data from tables? for
> example :
>
>
> CREATE TYPE "public"."cst_test" AS (
> "code" VARCHAR(10),
> "name" VARCHAR(50),
> "quantity" NUMERIC(10,2) );
>
> CREATE OR REPLACE FUNCTION public."sf_test"(id_code VARCHAR)
> RETURNS SETOF "public"."cst_test" AS
> $body$
> SELECT
> t1.code,
> t1.name,
> t2.quantity
> FROM "public"."test_1" t1
> INNER JOIN "public"."test_2" t2 ON t1.id_test1 = t2.id_test1
> WHERE t1.code = $1
> $body$
> LANGUAGE 'sql' ;
>
>
> It's STABLE, IMMUTABLE OR VOLATILE?
>

A function that modifies the database is VOLATILE.
A function that doesn't modify the database, but does database lookups,
is STABLE.
A function that doesn't modify the database, and doesn't do database
lookups (like SQRT(x)) is IMMUTABLE.

regards,
Leif B. Kristensen

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Matthew Walden 2010-11-22 12:10:55 Re: Help with date query
Previous Message maps 2010-11-22 11:30:31 function volatility