dbTalk Databases Forums  

insert with subquery into a locked table

comp.databases.mysql comp.databases.mysql


Discuss insert with subquery into a locked table in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jonbbbb
 
Posts: n/a

Default insert with subquery into a locked table - 03-08-2010 , 06:41 AM






Hi,

What I am trying to do:

CREATE TABLE IF NOT EXISTS profilename(profilename VARCHAR(255)
UNIQUE, INDEX(profilename), email VARCHAR(255), INDEX(email));

LOCK TABLES profilename WRITE;

INSERT INTO profilename (profilename,email) SELECT
concat('user',count(*)+1),'my (AT) email (DOT) com' from profilename;
ERROR 1100 (HY000): Table 'profilename' was not locked with LOCK
TABLES

So from searching the web for that error code I think you are suppose
to use:
LOCK TABLES profilename AS x WRITE;
Then use x in the query somehow? I really don't understand how this is
suppose to be so the locking works and one don't get the error. This
is based on what I saw in another thread, but it did not provide me
with enough
information to figure this out.

Thanks for any help,
Regards Jon Berg.

Reply With Quote
  #2  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: insert with subquery into a locked table - 03-08-2010 , 09:21 AM






jonbbbb wrote:
Quote:
Hi,

What I am trying to do:

CREATE TABLE IF NOT EXISTS profilename(profilename VARCHAR(255)
UNIQUE, INDEX(profilename), email VARCHAR(255), INDEX(email));

LOCK TABLES profilename WRITE;

INSERT INTO profilename (profilename,email) SELECT
concat('user',count(*)+1),'my (AT) email (DOT) com' from profilename;
ERROR 1100 (HY000): Table 'profilename' was not locked with LOCK
TABLES

So from searching the web for that error code I think you are suppose
to use:
LOCK TABLES profilename AS x WRITE;
Then use x in the query somehow? I really don't understand how this is
suppose to be so the locking works and one don't get the error. This
is based on what I saw in another thread, but it did not provide me
with enough
information to figure this out.

Thanks for any help,
Regards Jon Berg.
I guess my first question would be - what are you trying to do here?
Your logic isn't very good - for instance, if you ever delete a row from
the table, you will get duplicate entries.

If you're trying to get a unique id in the table, you should use an
auto_increment field.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.