From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Pragati Kenkare <pkenkare@writeme.com>
Cc: pgsql-novice@postgresql.org
Cc: pgsql-sql@postgresql.org
Subject: Re: 'select nextval('seq_name');' in a function ?
Date: Sat, 31 Jan 2004 07:23:36 -0800 (PST)
Message-ID: <20040131072014.L91270@megazone.bigpanda.com> (raw)
In-Reply-To: <20040124090410.63451.qmail@iname.com>
References: <20040124090410.63451.qmail@iname.com>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sszabo@megazone.bigpanda.com, pkenkare@writeme.com, pgsql-novice@postgresql.org
Subject: Re: 'select nextval('seq_name');' in a function ?
In-Reply-To: <20040131072014.L91270@megazone.bigpanda.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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