Re: selecting into a variable like @var=select ...

From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: joseph speigle <joe(dot)speigle(at)jklh(dot)us>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: selecting into a variable like @var=select ...
Date: 2003-12-17 16:36:35
Message-ID: 1071678995.8946.8497.camel@camel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 2003-12-16 at 13:12, Richard Huxton wrote:
> On Tuesday 16 December 2003 17:12, joseph speigle wrote:
> > hello list,
> >
> > I want to do something like the following:
> >
> > address=# @var = select max(id) from passwd;
> > ERROR: parser: parse error at or near "@" at character 1
>
> > so that I could then issue
> >
> > create sequence passwd_id_seq start @var increment 1
> >
> > how can I declare and capture output into this variable? Or, should I
> > create a function, if it is possible to issue a "create" statement inside a
> > procedure body?
>
> You'll have to use a function (plpgsql would be the obvious choice). You can
> issue almost all statements by building them up in a string and using
> EXECUTE.
>

why not just do:

begin;
create sequence passwd_id_seq;
select setval('passwd_id_seq',(select max(id) from passwd));
commit;

Robert Treat
--
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL

In response to

Browse pgsql-general by date

  From Date Subject
Next Message javier garcia - CEBAS 2003-12-17 16:36:55 Re: Excel, OpenOffice and Postgres
Previous Message Bob Powell 2003-12-17 16:01:46 Excel, OpenOffice and Postgres