views:

259

answers:

3

I am aware that MySQL and PostgreSQL[1] do not have that concept, so I am interested in finding out of there is an open-source SQL database that does have the concept.

[1] It was later pointed out that PostgreSQL does have the rowid pseudo-column.

A: 

if neither of them have done that, then no others do.

Francis
A: 

SQLite has an auto incremented "ROWID" column which you can access using ROWID, _ROWID, or OID. If you define an integer primary key than they will be aliased.

Steven Canfield
Not quite the same thing- the oracle feature is the row # of the results of a particular query. So if you order by the id desc, the first result would still have rowid #1.
Joel Coehoorn
Ah I didn't understand that. Is there a use case for that (where you couldn't just do it by hand) ?
Steven Canfield
It's a way to get TOP(x) in a db that doesn't support that structure if you use a subquery:SELECT * from ( SELECT * myTable ORDER BY interestingField) WHERE rowid > 101
Gary.Ray
Sorry - that query should be: SELECT * from ( SELECT FROM * myTable ORDER BY interestingField ) WHERE rowid < 101
Gary.Ray
ROWID is NOT the same thing as ROWNUM. ROWNUM is the relative order of a result in a query. ROWID is a physical identifier that is static, unless records are physically relocated. It's almost always unique in the database.
DCookie
+3  A: 

PostgreSQL does have this concept.

See here for a brief list of pseudocolumns in PostgreSQL, out of which ctid is of interest to you:

ctid (tuple identifier)

The identifier which describes the physical location of the tuple within the database. A pair of numbers are represented by the ctid: the block number, and tuple index within that block.

That is direct analog of Oracle's rowid.

As for MySQL, physical location of a row is not available for the front end.

In MyISAM, rowid is just a file offset from the beginning, and that's what is stored in the index leaves.

In InnoDB, tables are index organized by design, that means they always have some kind of a primary key, and the indexes over an InnoDB table use that PRIMARY KEY as a row pointer.

This is also true for Oracle's index organized tables, for which a rowid is not a physical pointer to a block in a datafile, but rather a such called logical ROWID, or UROWID

If you select a ROWID from an INDEX ORGANIZED table in Oracle, you will see that it has a different format (something like *BAEBwPICwQL+). This is in fact an encoded PRIMARY KEY value.

Note that if you have not defined any column as a PRIMARY KEY, MySQL will create a hidden surrogate PRIMARY KEY over which you will never have any control.

That's why you should always create some kind of a PRIMARY KEY in an InnoDB table: it's free, and you get control over the column.

Quassnoi
It does?I Googled for the answer, and found a forum post saying that PostgresQL does not have that concept.
Rishabh Mishra
Just try it if you don't believe me :)
Quassnoi
By the way: by ROWID in Oracle you mean ROWID (physical pointer to a data block containing a record) or ROWNUM (incremental row number in a dataset returned from a SELECT query)? These are different things.
Quassnoi