pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed'select nextval('seq_name');' in a function ?
2+ messages / 2 participants
[nested] [flat]
* 'select nextval('seq_name');' in a function ?
@ 2004-01-24 09:04 Pragati Kenkare <pkenkare@writeme.com>
2004-01-31 15:23 ` Re: 'select nextval('seq_name');' in a function ? Stephan Szabo <sszabo@megazone.bigpanda.com>
0 siblings, 1 reply; 2+ messages in thread
From: Pragati Kenkare @ 2004-01-24 09:04 UTC (permalink / raw)
To: pgsql-novice@postgresql.org; +Cc: 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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: 'select nextval('seq_name');' in a function ?
2004-01-24 09:04 'select nextval('seq_name');' in a function ? Pragati Kenkare <pkenkare@writeme.com>
@ 2004-01-31 15:23 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
0 siblings, 0 replies; 2+ messages in thread
From: Stephan Szabo @ 2004-01-31 15:23 UTC (permalink / raw)
To: Pragati Kenkare <pkenkare@writeme.com>; +Cc: pgsql-novice@postgresql.org; pgsql-sql
On Sat, 24 Jan 2004, Pragati Kenkare wrote:
> 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';
You need to double the single quotes around principal_id, and I'm not sure
which version switched to int8 sequences, and do you really want to be
passing in an unused int?
CREATE FUNCTION getnext_principal_id() returns int as 'select
CAST(nextval(''principal_id'') AS int4);' language 'SQL';
However, how are you planning to use this? Perhaps making principal_id a
serial would be better for you.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2004-01-31 15:23 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-01-24 09:04 'select nextval('seq_name');' in a function ? Pragati Kenkare <pkenkare@writeme.com>
2004-01-31 15:23 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox