Mashed-up emojis stored in a Postgres database not returned as single emoji using Python 3.9 with psycopg3. For example ‍ returned \u200d

Viewed 109

I am reading text containing emojis from a Postgres 13 database. Turns out that my Python/psycopg query does not decode/return the text as I would expect.

Via Postgres psql client

  • Within postgres:13 container

    select description from profile WHERE id = 123

Result is as expected!

️‍ and ‍‍⚕️

Via Python 3.9 with psycopg3 adapter

  • Within a python:3.9 container
  • same query as above

The result is not correctly retuned - fails to combine

>>> cur = conn.cursor()
>>> profiles = cur.fetchone()
>>> profiles[0]

️\u200d and \u200d\u200d⚕️

Connection object says it is using utf-8

>>> conn.info.encoding
'utf-8'

What am I missing here?

Any idea what I should be looking for?

Many thanks for your thoughts in advance, much appreciated! Eu

2 Answers

The emojis consist of several characters, and the shell you are using does not know how to display them in the way you want.

JosefZ posted a link for more details: https://emojipedia.org/emoji-sequence/

I have analysed string by raw bytes (provided in comment). The profiles[0] variable holds the valid string. The problem is only in the way the string is displayed, the more advanced emojis (using ZWJ \u200d) are not supported.

To get preview, You can dump the content to a text file and open in in a web browser.

Related