Re: Functions as default values

2003-08-14 Thread Cybot
I am trying to use a function as a default value for a column but do not
seem to get the desired result. I want to use the NOW() function for a
last_updated column, here is my code...
CREATE TABLE test_table (
  last_updated datetime NOT NULL default `NOW()`
) TYPE=MyISAM;
This gives an error;

CREATE TABLE test_table (
  last_updated datetime NOT NULL default 'NOW()'
) TYPE=MyISAM;
Now the table shows a default value of -00-00 00:00:00, when I add a new
row the value of last_updated is also -00-00 00:00:00. I am using MySQL
3.23.37, can anyone help?
funcion as default-value is not allowed AFAIK

but timestamp will help you to get what you want!
http://www.mysql.com/doc/en/DATETIME.html
--
Sebastian Mendel
www.sebastianmendel.de
www.tekkno4u.de
www.nofetish.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]


RE: Functions as default values

2003-08-06 Thread Phil Ewington - 43 Plc
No functions as default values is a bummer, but timestamp will do he trick,
so thanks for your help; much appreciated.


Phil.

-Original Message-
From: Cybot [mailto:[EMAIL PROTECTED]
Sent: 06 August 2003 15:37
To: [EMAIL PROTECTED]
Subject: Re: Functions as default values


> I am trying to use a function as a default value for a column but do not
> seem to get the desired result. I want to use the NOW() function for a
> last_updated column, here is my code...
>
> CREATE TABLE test_table (
>   last_updated datetime NOT NULL default `NOW()`
> ) TYPE=MyISAM;
>
> This gives an error;
>
> CREATE TABLE test_table (
>   last_updated datetime NOT NULL default 'NOW()'
> ) TYPE=MyISAM;
>
> Now the table shows a default value of -00-00 00:00:00, when I add a
new
> row the value of last_updated is also -00-00 00:00:00. I am using
MySQL
> 3.23.37, can anyone help?

funcion as default-value is not allowed AFAIK

but timestamp will help you to get what you want!
http://www.mysql.com/doc/en/DATETIME.html


--
Sebastian Mendel

www.sebastianmendel.de
www.tekkno4u.de
www.nofetish.com


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Functions as default values

2001-09-24 Thread Rodney Broom

From: Gerald Clark <[EMAIL PROTECTED]>
> Default values must be constants.

> Håkan Elmqvist wrote:
> > Now I want to register who changed it...

===> MY two cents worth:

With MySQL, this sort of thing usually gets handled in a piece of software. In Perl, 
we might say something like:

$sth = $dbh->prepare(qq{INSERT INTO my_table (user, data) VALUES (?,?)});
$sth->execute(user(), $data);


I know that I'd like to be able to define internal divisiveness like:

CREATE TABLE my_table (
  id int unsigned default my_sequence_routine(),
  ...
);

But I wouldn't be willing to have this in the engine if it meant a performance hit 
during the times when I wasn't this functionality.


---
Rodney Broom
Programmer: Desert.Net



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: Functions as default values

2001-09-24 Thread Gerald Clark

You can't.
Default values must be constants.

Håkan Elmqvist wrote:

> Timestamp is a useful datatype when you want to register when a record 
> changed. Now I want to register who changed it and tried to use user() 
> as a default value and my database just returned user() as the field 
> value. Is there someone who can tell me how to use a function result as 
> default value? The manual is not very clear on this issue.
> H
> 
> 
> Professor Håkan Elmqvist
> Avdelningen för medicinsk teknik
> Institutionen för medicinsk laboratorievetenskap & teknik
> KAROLINSKA INSTITUTET
> Novum
> 141 57 Huddinge
> Tel 46-8-585 837 55, Fax 46-8-779 55 50
> epost [EMAIL PROTECTED]
> Organisationsno. 01 202100-2973 01
> Vat No. SE 202100297301
> 
> -
> Before posting, please check:
>   http://www.mysql.com/manual.php   (the manual)
>   http://lists.mysql.com/   (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-- 
Gerald L. Clark
[EMAIL PROTECTED]


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php