Re: selecting into a variable like @var=select ... - Mailing list pgsql-general

From joseph speigle
Subject Re: selecting into a variable like @var=select ...
Date
Msg-id 20031216204011.GA5774@www.sirfsup.com
Whole thread Raw
In response to Re: selecting into a variable like @var=select ...  (Richard Huxton <dev@archonet.com>)
List pgsql-general
thanks for your help.  I have put off this project.  Of the two mysql2pgsql scripts at
http://developer.postgresql.org/docs/pgsql/contrib/mysql,I edited "mysql2pgsql" (perl script) for a few hours to
convertmysql enum ('abc','def') to create a new table which would be referenced from the postgres table to provide the
enumquality under the guise of "constraint REFERENCES ${table_name}_${column_name}_constraint_table."  However, I will
stopthere and will not fix the sequence creation part of
http://developer.postgresql.org/docs/pgsql/contrib/mysql/mysql2pgsql(same file as the one at
http://sourceforge.net/projects/docman/)which is broken at this moment.  I submitted my fix as a patch to
http://sourceforge.net/projects/docman/which should reach the gentleman in charge of it.  However I think the better
workingcopy is http://developer.postgresql.org/docs/pgsql/contrib/mysql/my2pg.pl which appears to have a working
sequencegeneration routine. 

On Tue, Dec 16, 2003 at 06:12:40PM +0000, 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.
>
> --
>   Richard Huxton
>   Archonet Ltd
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html

--
joe speigle

pgsql-general by date:

Previous
From: "Matt Gordon"
Date:
Subject: Re: VACUUM ANALYZE -vs- ANALYZE on an insert-only table.
Next
From: "Somasekhar Bangalore"
Date:
Subject: Re: [ADMIN][HACKERS]data fragmentation