List:General Discussion« Previous MessageNext Message »
From:Martijn Tonies Date:January 2 2007 2:29pm
Subject:Re: sequences and auto_increment
View as plain text  
Hi,

> I'm new to MySQL coming from PostgreSQL backgroud. I'd like to know how to
> obtain the same effect of a sequence + concat as default value of a table
in
> mysql. For example, consider the following table definition:
>
> CREATE TABLE competenza
> (
>   id_competenza character varying(30) NOT NULL DEFAULT ('comp-06-'::text
||
> (nextval('sequenza_competenza'::regclass))::text),
>   descrizione character varying(100),
>   CONSTRAINT competenza_pkey PRIMARY KEY (id_competenza)
> )
>
> there, id_competenza is compound by a string "comp-06" and the next value
of a
> sequence (similar to auto_increment). In MySQL there're no sequences, or
> better, there's only an auto_increment action on an int field. How can I
> obtain the same effect of the concatenation of a sequence and a string?

Hmm, well, I think: not at all.

Unless you implement something like sequences yourself.

MySQL doesn't allow functions to be used in the DEFAULT clause either.

Martijn Tonies
Database Workbench - development tool for MySQL, and more!
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com

Thread
sequences and auto_incrementLuca Ferrari2 Jan
  • Re: sequences and auto_incrementMartijn Tonies2 Jan
  • Re: sequences and auto_incrementBrent Baisley2 Jan
    • Re: sequences and auto_incrementLuca Ferrari2 Jan
      • Re: sequences and auto_incrementKen Brown2 Jan
  • Re: sequences and auto_incrementMartijn Tonies2 Jan