On Fri, Nov 13, 2009 at 8:07 AM, Marco Bambini <[email protected]> wrote:
> sqlite 3.6.19
>
> CREATE TABLE foo (col1 INTEGER PRIMARY KEY, col2 TEXT);
> a
> SELECT rowid, col1, col2
>
> returns the following column names with sqlite3_column_name:
> col1, col1, col2
>
> Is there a way to force the first column name to be returned as rowid and not
> as its col1 alias?
>
As Simon suggested, the only way really is to create your own rowid,
which will then override the automatic alias to the INTEGER PRIMARY
KEY column. Consider
sqlite> CREATE TABLE foo (rowid INTEGER, col1 INTEGER PRIMARY KEY, col2 TEXT);
sqlite> INSERT INTO foo (col2) VALUES ('blah');
sqlite> SELECT rowid, col1, col2 FROM foo;
rowid col1 col2
---------- ---------- ----------
1 blah
sqlite> SELECT _rowid_, rowid, col1 FROM foo;
col1 rowid col1
---------- ---------- ----------
1 1
sqlite>
If you are interested in getting a valid result from your rowid, you
could create a TRIGGER that automatically updates your custom rowid to
the value of col1.
--
Puneet Kishor http://www.punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
-----------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
=======================================================================
Sent from Madison, Wisconsin, United States
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users