简体   繁体   中英

retrieve columns from sqlite3

I have two tables in sqlite:

CREATE TABLE fruit ('fid' integer, 'name' text);
CREATE TABLE basket ('fid1' integer, 'fid2' integer, 'c1' integer, 'c2' integer);

basket is supposed to have count c1 of fruit fid1 and c2 of fruit fid2

I created a view fruitbasket;

create view fruitbasket as select * from basket inner join fruit a on a.fid=basket.fid1 inner join fruit b on b.fid=basket.fid2;

it works (almost) as expected.

When I type

pragma table_info(fruitbasket);

I get the following output

0|fid1|integer|0||0
1|fid2|integer|0||0
2|c1|integer|0||0
3|c2|integer|0||0
4|fid|integer|0||0
5|name|text|0||0
6|fid:1|integer|0||0
7|name:1|text|0||0

The problem is that I cannot seem to SELECT name:1. How can I do it other than going back and re-aliasing the columns?

Use double-quotes to indicate column names:

select "name:1" from fruitbasket;

Here's an example:

sqlite> insert into fruit values (1,'apple');
sqlite> insert into fruit values (2,'pear');
sqlite> insert into basket values(1,2,3,4);
sqlite> select "name:1" from fruitbasket;
pear
sqlite> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM