![]() |
#1 |
Member
![]() Posts: 22
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
|
Export books with tags with SQL
Hello
And first of all thank you for this extraordinary software that is Calibre. It's probably very simple, but my knowledge in SQL being limited, I'm looking for the query to export a book with all its tags. Thanks in advance. ![]() |
![]() |
![]() |
![]() |
#2 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,642
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Not sure why you think you need to use SQL to save a book.
The Preferences->Save to Disk settings are used to define what gets saved, check the Update metadata in saved copies to put the tags etc into the saved format file(s). Then use one of the Save to Disk options to save the book to the selected location. BR |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,726
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Could they be using calibredb rather than the GUI? I don't mess around much with the cmdline tools myself, so I'm not sure.
|
![]() |
![]() |
![]() |
#4 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,914
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Calibre has 2 main parts per book:
1) the DB entry (actually many pieces: as it is a relational DB) 2) The books format(s) just stored in the file system The DB entry contains a PATH to the book as well as lots of metadata. Ownedbycats is referring to the command line tools, that can be used to perform tasks.(see the online help) No need to know SQL as all the tools do the needed lifting (without risking library integrity). |
![]() |
![]() |
![]() |
#5 | |
Member
![]() Posts: 22
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
|
Quote:
Sorry, I wasn't clear. ![]() What I want is to export the book's metadata, not save it. And I want to do it with an SQL query on the db database because it takes a lot of time to do it from Calibre considering the size of my library (more than 100,000 books). ![]() |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,642
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Not sure if using SQL against the database file would be any faster than exporting a CSV catalog from the calibre GUI (you may need to add the Create Catalog tool to a Toolbar or menu), or via the calibredb list command ==>> The Command Line Interface
The database is loaded into memory when calibre is running. However if you're determined to use SQL direct, I would suggest you copy the metadata.db file at the root of the library, and use something like DB Browser for SQLite to do queries against it to export CSV, HTML etc. You'll need to spend a few minutes examining the schema but its fairly straightforward. BR |
![]() |
![]() |
![]() |
#7 | |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,726
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quote:
|
|
![]() |
![]() |
![]() |
#8 | |
Member
![]() Posts: 22
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
|
Quote:
![]() And my question is what is the query to export ALL the tags. I use this one and it doesn't work. SELECT id, author_sort, title, (SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher, (SELECT format FROM data WHERE data.book=books.id) formats, path, (SELECT name FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags FROM books |
|
![]() |
![]() |
![]() |
#9 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,345
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
![]() |
![]() |
![]() |
#10 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,345
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
BTW, the reason your SQL doesn't work is that some of the subqueries return multiple rows. You only see the first one. To see all of them you need to use group_concat(), like this:
Code:
SELECT id, author_sort, title, (SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher, (SELECT group_concat(format) FROM data WHERE data.book=books.id) formats, path, (SELECT group_concat(name) FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags FROM books |
![]() |
![]() |
![]() |
#11 | |
Member
![]() Posts: 22
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
|
Quote:
![]() The query works perfectly ![]() Thanks again for your help. |
|
![]() |
![]() |
![]() |
#12 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,914
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
https://calibre-ebook.com/about#contributors (and yes!, he is brilliant) |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can you export a list of tags? | bhagerty | Library Management | 17 | 12-14-2022 04:00 PM |
Where are the tags on export to the file system? | halloleo | Library Management | 3 | 03-24-2020 10:56 PM |
SQL error attempting to remove books from library | Aelbfled | Calibre | 1 | 12-30-2017 10:49 AM |
Export tags | Daedalus.p1 | Calibre | 4 | 02-25-2013 04:15 PM |