I am trying to amend the value of a key in a table.
I have a database (this is for Immich if relevant). See below details of the table. I am trying to amend "library.watch.usePolling" from "true" to "false". I am using this command and getting an error. I am not sure, what this error means, nor whether I am using the correct command. I know this must be an easy question, but I am very much a beginner with PostgreSQL.
UPDATE system_config
SET value = false
WHERE key = library.watch.usePolling
;
ERROR: missing FROM-clause entry for table "watch"
LINE 3: WHERE key = library.watch.usePolling
These are the details of the table in the database as it currently exists.
d+ system_config
Table "public.system_config"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
--------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
key | character varying | | not null | | extended | | |
value | character varying | | | | extended | | |
Indexes:
"PK_aab69295b445016f56731f4d535" PRIMARY KEY, btree (key)
Access method: heap
SELECT * from "system_config";
key | value
-------------------------------------+---------------
ffmpeg.transcode | "disabled"
job.objectTagging.concurrency | 4
job.clipEncoding.concurrency | 4
job.sidecar.concurrency | 4
job.migration.concurrency | 4
job.library.concurrency | 80
job.thumbnailGeneration.concurrency | 20
job.metadataExtraction.concurrency | 50
job.recognizeFaces.concurrency | 6
storageTemplate.enabled | true
ffmpeg.accel | "qsv"
library.scan.cronExpression | "0 */6 * * *"
job.smartSearch.concurrency | 60
job.faceDetection.concurrency | 60
library.watch.enabled | true
library.watch.usePolling | true
(16 rows)
Note: I have also tried this command:
SET "system_config.value" = "false" WHERE "system_config.key" = "library.watch.usePolling";
I’ve tried a few options. Main ones here:
UPDATE system_config
SET value = false
WHERE key = library.watch.usePolling
;
ERROR: missing FROM-clause entry for table "watch"
LINE 3: WHERE key = library.watch.usePolling
and
SET "system_config.value" = "false" WHERE "system_config.key" = "library.watch.usePolling";
ERROR: syntax error at or near "WHERE"
LINE 1: SET "system_config.value" = "false" WHERE "system_config.key...
2
Answers
Turns out that I actually didnt need to amend the value at all - so deleting the value from the table was all I needed.
solution:
then
For starters, I wouldn’t use either
key
orvalue
as field names – if you look here, you will see that both words occur in that list. They also appear in the PostgreSQL list (but as non-reserved) – again, avoid any words on this list – belt and braces! I would recommend that you change the names of your fields to (something like)sc_key
andsc_value
– these are also more meaningful.All of the code below is available on the fiddle here.
From here (manual):
so,
and the same for
value
.Also, rename – (manual – search for
RENAME CONSTRAINT
) thatPRIMARY KEY
– an error message telling a user that there has been a violation ofPK_aab69295b445016f56731f4d535
is absolutely meaningless – change it to something likesc_pk
(orsystem_config_pk
).BTW, there is never any need to (double) quote your identifiers (e.g. table, column or constraint) names unless for some reason, you wish to, (and/or) are obliged to, respect case, punctuation or spaces in identifiers.
If not, my strong recommendation is to use snake_case for everything (lower case with underscores separating words to make it readable). There are various SQL style guides on the internet (this one is good) – but pick a style and stick to it – consistency in this area helps legibility and makes debugging easier. I would also never put punctuation or spaces in my identifier names – you’re just making life difficult for yourself by doing this – it also means that in the event of a change of database server, your code will be less- or completely non-portable!
Run a couple of queries to double check our changes (found code here & here) – column names:
Result:
the
null
is because there is no length specified – aVARCHAR
can be up to 1GB.and
PRIMARY KEY
:Result:
Now, to your question proper.
Double quotes are used for identifiers (table and column names) – to specify a string (in this case
CHARACTER VARYING
), you use single quotes!To resolve your issue, I did the following:
I created and then modified the table as specified above (see fiddle), and then I inserted your data:
Note the use of single quotes to delineate strings – PostgreSQL appears to recognise numbers and true as valid strings (which surprised me, I must confess).
See the query using the
PG_TYPEOF()
function in the fiddle – they all come out asCHARACTER VARYING
.Result (sample):
So, now to modify the value of
library.watch.usePolling
.and again, we check:
Result:
So, you have to be careful to distinguish between double quotes for identifiers and single quotes for delineating strings!
On a final note, unless there’s a compelling reason not to do so, I would always use the
TEXT
datatype (maximum size also 1GB) for any sort of, well…, text data. From here:See the fiddle for this query:
Result:
So, we see that
TEXT
is indeed the preferred type when it comes to character/text data.And from the same post (read it in full – and follow up on the links – all of this poster’s contributions are very instructive):
Check out the poster’s rep – so my final piece of advice is to change your column types (manual) to
TEXT
rather thanVARCHAR
/CHARACTER VARYING
.and the same for
sc_value
.Check using the
PG_TYPEOF()
query from before – result (sample):