Re: [sqlite] how to add a new column quickly

2007-05-07 Thread ronggui wong

Yes, it is fine.

Thanks very much.


2007/5/7, Mohd Radzi Ibrahim <[EMAIL PROTECTED]>:


How about this?


update tablename set newcolname=(case rowid when 1 then 1 else 2 end);


best regards,
Radzi


- Original Message -
From: "Tomash Brechko" <[EMAIL PROTECTED]>
To: <sqlite-users@sqlite.org>
Sent: Saturday, May 05, 2007 8:09 PM
Subject: Re: [sqlite] how to add a new column quickly


> On Sat, May 05, 2007 at 19:30:59 +0800, ronggui wong wrote:
>> Thanks. But there is no typo, what I want is a general solution.
>>
>> 2007/5/5, Tomash Brechko <[EMAIL PROTECTED]>:
>> >On Sat, May 05, 2007 at 14:01:56 +0800, ronggui wong wrote:
>> >> . update tablename set newcolname=1 where ROWID=1
>> >> . update tablename set newcolname=2 where ROWID=2
>> >> . update tablename set newcolname=2 where ROWID=3
>
> If there is no correlation between newcolname and other columns that
> can be expressed as a formula, but rather you want to set newcolname
> to some known Func(ROWID), you may register this function with
> sqlite3_create_function() (or its equivalent for your language
> bindings), and then do a single statement
>
>  UPDATE tablename SET newcolname = Func(ROWID);
>
> This will be faster then repeatedly searching for a row with a given
> ROWID.
>
>
> --
>   Tomash Brechko
>
> -
> To unsubscribe, send email to [EMAIL PROTECTED]
> -
>
>



-
To unsubscribe, send email to [EMAIL PROTECTED]
-




-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] how to add a new column quickly

2007-05-06 Thread Mohd Radzi Ibrahim


How about this?


update tablename set newcolname=(case rowid when 1 then 1 else 2 end);


best regards,
Radzi


- Original Message - 
From: "Tomash Brechko" <[EMAIL PROTECTED]>

To: <sqlite-users@sqlite.org>
Sent: Saturday, May 05, 2007 8:09 PM
Subject: Re: [sqlite] how to add a new column quickly



On Sat, May 05, 2007 at 19:30:59 +0800, ronggui wong wrote:

Thanks. But there is no typo, what I want is a general solution.

2007/5/5, Tomash Brechko <[EMAIL PROTECTED]>:
>On Sat, May 05, 2007 at 14:01:56 +0800, ronggui wong wrote:
>> . update tablename set newcolname=1 where ROWID=1
>> . update tablename set newcolname=2 where ROWID=2
>> . update tablename set newcolname=2 where ROWID=3


If there is no correlation between newcolname and other columns that
can be expressed as a formula, but rather you want to set newcolname
to some known Func(ROWID), you may register this function with
sqlite3_create_function() (or its equivalent for your language
bindings), and then do a single statement

 UPDATE tablename SET newcolname = Func(ROWID);

This will be faster then repeatedly searching for a row with a given
ROWID.


--
  Tomash Brechko

-
To unsubscribe, send email to [EMAIL PROTECTED]
-






-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] how to add a new column quickly

2007-05-05 Thread Tomash Brechko
On Sat, May 05, 2007 at 19:30:59 +0800, ronggui wong wrote:
> Thanks. But there is no typo, what I want is a general solution.
> 
> 2007/5/5, Tomash Brechko <[EMAIL PROTECTED]>:
> >On Sat, May 05, 2007 at 14:01:56 +0800, ronggui wong wrote:
> >> . update tablename set newcolname=1 where ROWID=1
> >> . update tablename set newcolname=2 where ROWID=2
> >> . update tablename set newcolname=2 where ROWID=3

If there is no correlation between newcolname and other columns that
can be expressed as a formula, but rather you want to set newcolname
to some known Func(ROWID), you may register this function with
sqlite3_create_function() (or its equivalent for your language
bindings), and then do a single statement

  UPDATE tablename SET newcolname = Func(ROWID);

This will be faster then repeatedly searching for a row with a given
ROWID.


-- 
   Tomash Brechko

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] how to add a new column quickly

2007-05-05 Thread ronggui wong

Thanks. But there is no typo, what I want is a general solution.

2007/5/5, Tomash Brechko <[EMAIL PROTECTED]>:

On Sat, May 05, 2007 at 14:01:56 +0800, ronggui wong wrote:
> . update tablename set newcolname=1 where ROWID=1
> . update tablename set newcolname=2 where ROWID=2
> . update tablename set newcolname=2 where ROWID=3
> .
>
> My question is: how to add the above task efificiently? Thanks!

If there is a typo in the last line, and it should have been
'newcolname=3' (not 2), then your operation is effectively

  UPDATE tablename SET newcolname = ROWID;


--
   Tomash Brechko

-
To unsubscribe, send email to [EMAIL PROTECTED]
-




-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] how to add a new column quickly

2007-05-05 Thread Tomash Brechko
On Sat, May 05, 2007 at 14:01:56 +0800, ronggui wong wrote:
> . update tablename set newcolname=1 where ROWID=1
> . update tablename set newcolname=2 where ROWID=2
> . update tablename set newcolname=2 where ROWID=3
> .
> 
> My question is: how to add the above task efificiently? Thanks!

If there is a typo in the last line, and it should have been
'newcolname=3' (not 2), then your operation is effectively

  UPDATE tablename SET newcolname = ROWID;


-- 
   Tomash Brechko

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] how to add a new column quickly

2007-05-05 Thread ronggui wong

I would like to add a new column to an existing table. I use
.alter table tablename add newcolname
to add a new col, and use
. update tablename set newcolname=1 where ROWID=1
. update tablename set newcolname=2 where ROWID=2
. update tablename set newcolname=2 where ROWID=3
.

My question is: how to add the above task efificiently? Thanks!

Ronggui Huang

-
To unsubscribe, send email to [EMAIL PROTECTED]
-