pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John DeSoi <desoi@pgedit.com>
To: Julio Leyva <jcleyva@hotmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: alter sequence in a function
Date: Wed, 4 Jul 2007 08:11:41 -0400
Message-ID: <FA54F2B7-2F04-4446-80C3-70946D594AD7@pgedit.com> (raw)
In-Reply-To: <BAY120-W180EC0773E6E0BC38E448DA10C0@phx.gbl>
References: <BAY120-W180EC0773E6E0BC38E448DA10C0@phx.gbl>


On Jul 3, 2007, at 6:48 PM, Julio Leyva wrote:

> create or replace function updatesafe()  returns integer AS $$
> DECLARE
> maxseq integer;
> alterseq varchar(256);
> thumb integer;
> newvalue integer;
> BEGIN
> newvalue := 10010;
>   maxseq := (select max(safeoperationid) from safeopencloseoperation);
>
>     if (maxseq < 500) then
>       return 3000;
>
>    else
>     execute 'ALTER sequence safeopencloseoperation_id_seq restart  
> with ' || 'newvalue ' ;
>     return 10000;
>  END IF;
> END;
> $$ language plpgsql
>
> It compiles ok but when I call the function
> it gives me this error
>
>  ALTER sequence safeopencloseoperation_id_seq restart with newvalue
> CONTEXT:  PL/pgSQL function "updatesafe" line 17 at execute statement
> LINE 1: ...equence safeopencloseoperation_id_seq restart with newvalue


You are appending the literal string "newvalue" not the string  
"100010". Change newvalue to text and cast it from an integer, if  
necessary. Then you want:

  execute 'ALTER sequence safeopencloseoperation_id_seq restart with  
' || newvalue ;



John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL




view thread (3+ messages)

Message-ID: <FA54F2B7-2F04-4446-80C3-70946D594AD7@pgedit.com>
Permalink:  ../FA54F2B7-2F04-4446-80C3-70946D594AD7@pgedit.com/
Also on:    postgresql.org/message-id/FA54F2B7-2F04-4446-80C3-70946D594AD7@pgedit.com

 · 

reply

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-admin@postgresql.org
  Cc: desoi@pgedit.com, jcleyva@hotmail.com
  Subject: Re: alter sequence in a function
  In-Reply-To: <FA54F2B7-2F04-4446-80C3-70946D594AD7@pgedit.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