SQLite3 and lastrowid

Alexander Gattin xrgtn at yandex.ru
Fri Nov 19 06:28:53 EST 2010


On Fri, Nov 19, 2010 at 01:14:34PM +0200,
Alexander Gattin wrote:
> On Tue, Nov 16, 2010 at 01:52:42PM -0800, Ian
> wrote:
> > The proper way to get the number of rows is to
> > use the COUNT aggregate function, e.g., "SELECT
> > COUNT(*) FROM TABLE1", which will return a
> > single row with a single column containing the
> > number of rows in table1.
> 
> It's better to select count(1) instead of
> count(*). The latter may skip rows consisting
> entirely of NULLs IIRC.

sorry, I'm wrong -- count(*) behaves the same way
as count(1) does:

sqlite> create table t (x number, y char);
sqlite> insert into t(x,y) values(1,'a');
sqlite> insert into t(x,y) values(2,NULL);
sqlite> insert into t(x,y) values(NULL,'c');
sqlite> insert into t(x,y) values(NULL,NULL);
sqlite> insert into t(x,y) values(NULL,NULL);
sqlite> select count(1),count(*),count(x),count(y) from t;
5|5|2|2
sqlite> 

P.S. Surprise -- it's true even for Oracle SQL...

-- 
With best regards,
xrgtn (+380501102966/+380636177128/xrgtn at jabber.kiev.ua)



More information about the Python-list mailing list