Anki/rslib/src/search/note_original_position_order.sql
Taylor Obyen 7439c657f0
Add card position column and always show position in card info (#3471)
* Expose original position to columns and card info

* Fix contributors

* Change routine name and return, fix SQL file, utilize coalesce inline

* Handle cards without original position

* Remove unecessary conversion
2024-10-11 20:14:07 +10:00

16 lines
No EOL
313 B
SQL

DROP TABLE IF EXISTS sort_order;
CREATE TEMPORARY TABLE sort_order (
pos integer PRIMARY KEY,
nid integer NOT NULL UNIQUE
);
INSERT INTO sort_order (nid)
SELECT nid
FROM cards
GROUP BY nid
ORDER BY COALESCE(
extract_original_position(data),
CASE
WHEN type == 0 THEN due
ELSE 0
END
);