Closed StefanBrand closed 3 years ago
3rd attempt should be right. KeyTextTransform seems to be working. I don't know why KeyTextTransform is included and KeyTransform not. first is '->>' operator, second is '->'. No differences in final query. Maybe ST_ASMVT doesn't like simple '->'
OK, I understand. https://www.postgresql.org/docs/9.3/functions-json.html
According documentation, "->" operator return JSONB single value. Django can decode it as SQL values, but it seems that ST_ASMVT doesn't.
For text or nontyped values, you should use KeyTextTransform.
Feature.objects.annotate(foo=KeyTextTransform('foo', 'json'))
For other, you should cast :
Feature.objects.annotate(foo=Cast(KeyTextTransform('foo', 'json'), output_field=IntegerField()))
You are a genius! Works splendidly!
I'm closing as this is a ST_ASMVT
limitation.
Il will add this workaround in documentation
I'd like to retrieve values from a
JSONField
because all contents of the whole JSON bloat the vector tiles. Doesn't seem to be possible. Do you see a way?I tried this (adapted from test suite):
1st Attempt (related field notation)
results in (Nothing included in MVT)
2nd Attempt (annotate related field notation)
results in (whole JSON included in MVT)
3rd Attempt (
KeyTransform
)results in (Nothing contained in MVT)