smile2day
smile2day

Reputation: 1665

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

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

Result is as expected!

🏳️‍🌈 and 👩‍💻👩‍⚕️

Via Python 3.9 with psycopg3 adapter

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

Upvotes: 2

Views: 322

Answers (2)

Michas
Michas

Reputation: 9428

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.

Upvotes: 1

Laurenz Albe
Laurenz Albe

Reputation: 246403

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/

Upvotes: 1

Related Questions