Re: PostgreSQL sequence within function - Mailing list pgsql-general

From Russ Brown
Subject Re: PostgreSQL sequence within function
Date
Msg-id 42C4E3B6.50800@gmail.com
Whole thread Raw
In response to Re: PostgreSQL sequence within function  (Tony Caduto <tony_caduto@amsoftwaredesign.com>)
Responses Re: PostgreSQL sequence within function
List pgsql-general
Tony Caduto wrote:
> All you where really mising was a semi colon afer nextval('myseq') and
> the begin end.
>
> CREATE or REPLACE FUNCTION getSeq()
> RETURNS int AS
> $$
> begin
> RETURN nextval('myseq');
> end;
> $$
> LANGUAGE 'plpgsql';
>
> Clark Allan wrote:
>

This just made me think. If I was writing this function, I would have
written it as an SQL function like this:

CREATE or REPLACE FUNCTION getSeq() RETURNS int AS $$
SELECT nextval('myseq');
$$ LANGUAGE SQL;

Does anybody know which version is actually better/faster/more optimal?
I tend to always write functions as SQL where it's possible, as I
imagine that an SQL database engine will be better at running an SQL
functionion than an interpreted procedural function. Am I right to think
that?

--

Russ.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Check constraint problem
Next
From: Russ Brown
Date:
Subject: Re: COnsidering a move away from Postgres