On 4 Jul 2009, at 8:49pm, James Scott wrote:

> CREATE INDEX [PK_Sections] ON [Sections] ([Department], [Course],
> [Section]);
>
> In the programming language, I need to refer to the primary key as 1  
> field.
> Does Sqlite allow a 'calculated field', such as concatenation of the 3
> columns in the PK?  Or can I create a View to combine the 3?

SELECT department||course||section FROM sections

or

SELECT department||course||section FROM sections ORDER BY  
department,course,section

whichever suits you best.  You can use '||' to concatenate anywhere an  
expression is allowed.

As usual, it's not your job to work out which index is best: SQLite  
does it for you.  And because of the way SQLite works it will never  
actually look at the table to find those values: it needs to use the  
index anyway and will realise it can take the values directly from the  
index without having to do the extra lookup to get them from the table.

Simon.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to