Skip to content

Slightly safer way to use pseudo/hidden columns? #22

Open
@debug-ito

Description

@debug-ito

In SQLite3, we can use rowid pseudo-column and last_insert_rowid() function to query the last inserted record.

To build such a query with HRR, I tried

lastInsertRecord :: Table r -> Pi r v -> Relation () v
lastInsertRecord tab selector = relation $ do
  record <- query $ table tab
  let rowid = unsafeProjectSql "rowid"
      last_rowid = unsafeProjectSql "last_insert_rowid()"
  wheres $ rowid .=. last_rowid
  return (record ! selector)

This gives me a Relation like:

>>> lastInsertRecord tableOfSample id'
SELECT ALL T0.sample_id AS f0, T0.val AS f1 FROM MAIN.sample T0 WHERE (rowid = last_insert_rowid())

This works. However, because rowid is a pseudo-column of sample table, it should be T0.rowid in the above query.

So, is there any way to specify rowid as a pseudo-column of a table?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions