'select nextval('seq_name');' in a function ?

From: "Pragati Kenkare" <pkenkare(at)writeme(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Cc: pgsql-sql(at)postgresql(dot)org
Subject: 'select nextval('seq_name');' in a function ?
Date: 2004-01-24 09:04:10
Message-ID: 20040124090410.63451.qmail@iname.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-sql

Hi,

I am new to postgresql. Using PostgreSQL 7.3.2, I did the following.

testdb#CREATE SEQUENCE principal_id increment 1 start 1000 cache 5;

testdb#CREATE TABLE principal (principal_id int not null, name text, constraint pk_principal primary key(principal_id));

testdb#CREATE FUNCTION getnext_principal_id(int) returns int as 'select nextval('principal_id');' language 'SQL';

This gives ->
ERROR: parser: parse error at or near "principal_id" at character ...

Please help. Basically, I want to write equivalent of the following Oracle procedure:

create or replace procedure getnext_principal_id (retVal out principal.principal_id%TYPE ) as
begin
select principal_id.nextval into retValue from dual;
end;

Thanks much,
Pragati
--
_______________________________________________
Get your free email from http://www.iname.com

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Peggy Go 2004-01-24 13:19:59 error when running ./configure
Previous Message Oliver Elphick 2004-01-23 23:11:33 Re: Problem with pg_hba.conf file in Postgres 7.3

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2004-01-26 10:50:48 Re: [SQL] Database diagram
Previous Message David Arnold 2004-01-24 06:24:37 An order by question