Skip to content

High performance self-hosted photo and video management solution.

docs: DB queries cleanups (#8740)

Matthew Momjian3eb61a9d530e
diff --git a/docs/docs/administration/postgres-standalone.md b/docs/docs/administration/postgres-standalone.md
index 42e77f70bb..be8d883a1c 100644
--- a/docs/docs/administration/postgres-standalone.md
+++ b/docs/docs/administration/postgres-standalone.md
@@ -63,4 +63,4 @@ When installing a new version of pgvecto.rs, you will need to manually update th
#### Permission denied for view
-If you get the error `driverError: error: permission denied for view pg_vector_index_stat`, you can fix this by connecting to the Immich database and running `GRANT SELECT ON TABLE pg_vector_index_stat to <immichdbusername>;`.
+If you get the error `driverError: error: permission denied for view pg_vector_index_stat`, you can fix this by connecting to the Immich database and running `GRANT SELECT ON TABLE pg_vector_index_stat TO <immichdbusername>;`.
diff --git a/docs/docs/guides/database-queries.md b/docs/docs/guides/database-queries.md
index cccfd5b31a..45112849fa 100644
--- a/docs/docs/guides/database-queries.md
+++ b/docs/docs/guides/database-queries.md
@@ -17,7 +17,7 @@ The `"originalFileName"` column is the name of the file at time of upload, inclu
:::
```sql title="Find by original filename"
-SELECT * FROM "assets" WHERE "originalFileName" = 'PXL_20230903_232542848';
+SELECT * FROM "assets" WHERE "originalFileName" = 'PXL_20230903_232542848.jpg';
SELECT * FROM "assets" WHERE "originalFileName" LIKE 'PXL_%'; -- all files starting with PXL_
SELECT * FROM "assets" WHERE "originalFileName" LIKE '%_2023_%'; -- all files with _2023_ in the middle
```
@@ -31,7 +31,7 @@ SELECT * FROM "assets" WHERE "originalPath" LIKE 'upload/library/admin/2023/%';
You can calculate the checksum for a particular file by using the command `sha1sum <filename>`.
:::
-```sql title="Find by checksum (SHA1)"
+```sql title="Find by checksum (SHA-1)"
SELECT encode("checksum", 'hex') FROM "assets";
SELECT * FROM "assets" WHERE "checksum" = decode('69de19c87658c4c15d9cacb9967b8e033bf74dd1', 'hex');
```
@@ -41,7 +41,7 @@ SELECT * FROM "assets" where "livePhotoVideoId" IS NOT NULL;
```
```sql title="Without metadata"
-SELECT "assets".* FROM "exif" LEFT JOIN "assets" ON "assets"."id" = "exif"."assetId" WHERE "exif"."assetId" IS NULL;
+SELECT "assets".* FROM "exif" LEFT JOIN "assets" ON "assets"."id" = "exif"."assetId" WHERE "exif"."assetId" IS NULL;
```
```sql title="size < 100,000 bytes, smallest to largest"
@@ -58,20 +58,15 @@ SELECT * FROM "assets" WHERE "assets"."type" = 'IMAGE';
```
```sql title="Count by type"
-SELECT "assets"."type", count(*) FROM "assets" GROUP BY "assets"."type";
+SELECT "assets"."type", COUNT(*) FROM "assets" GROUP BY "assets"."type";
```
```sql title="Count by type (per user)"
-SELECT
- "users"."email", "assets"."type", COUNT(*)
-FROM
- "assets"
-JOIN
- "users" ON "assets"."ownerId" = "users"."id"
-GROUP BY
- "assets"."type", "users"."email"
-ORDER BY
- "users"."email";
+SELECT "users"."email", "assets"."type", COUNT(*)
+ FROM "assets"
+ JOIN "users" ON "assets"."ownerId" = "users"."id"
+ GROUP BY "assets"."type", "users"."email"
+ ORDER BY "users"."email";
```
```sql title="Failed file movements"