List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:June 13 2001 3:47am
Subject:Re: user variables
View as plain text  
At 3:16 AM +0200 6/13/01, Luis A. Fdez. de Retana Aguirre wrote:
>Hello,
>
>  My problem is about users variables. I want to do
>a script to create a database so:
>   SET @dbname:="mydbname";
>   CREATE DATABASE @dbname;    #      <------ Don´t
>work
>   CREATE DATABASE (SELECT @dbname);# <------ Don´t
>Work

As the manual says, user-defined variables may be used wherever
an expression is legal.  However, expressions aren't legal database
names, so what you're trying to do isn't legal.

If you're trying to write a script, perhaps you can use variable
substitution at the level of your scripting language, rather than
at the SQL level.  For example:

#! /bin/sh

DB_NAME=mydbname

mysql <<EOF
CREATE DATABASE $DB_NAME;
EOF


>
>I have tried to define @dbname=mydbname directly
>but it blocks.
>
>Thanks


-- 
Paul DuBois, paul@stripped
Thread
user variablesLuis A. Fdez. de Retana Aguirre13 Jun
  • Re: user variablesPaul DuBois13 Jun