From: | Leon Starr <leon_starr(at)modelint(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Best way to create a sequence generator at run time? |
Date: | 2010-09-21 16:57:54 |
Message-ID: | CABF807A-A984-4791-B649-F39A76514EF0@modelint.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hi all,
I am trying to write plpgsql that must create a sequence generators during runtime. The min/max values are provided as function parameters.
The following isn't working for me and I'm not too surprised, but not sure of the best way to proceed. I am guessing I need to use PERFORM, EXECUTE or cursors or something?
==
create or replace function my_number_assigner(
p_floor int,
p_ceiling int
) returns void as
$$
create sequence num_generator minvalue p_floor maxvalue p_ceiling start with p_floor;
end
$$
language plpgsql;
==
ERROR: syntax error at or near "$1"
LINE 1: create sequence num_generator minvalue $1 maxvalue $2 s...
^
QUERY: create sequence num_generator minvalue $1 maxvalue $2 start with $1
CONTEXT: SQL statement in PL/PgSQL function "my_number_assigner" near line 35
I presume that the create sequence expression wants to see literals instead of variables, right? I knew I was going to run into this situation sooner or later. What should I be doing here?
- Leon
From | Date | Subject | |
---|---|---|---|
Next Message | Mladen Gogala | 2010-09-21 18:16:28 | Pgstatspack and pgfouine with auto_explain? |
Previous Message | Jens-Christoph Brendel | 2010-09-21 15:52:40 | Re: PostgreSQL article online - PDF |