Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display "invisible" unicode characters in psql / postgres?

How can I display normally invisible unicode characters from within psql (the postgres command line client)?

like image 711
Bryce Avatar asked Aug 17 '13 00:08

Bryce


People also ask

How do I find special characters in PostgreSQL?

Solution: Let's consider a table called spatial_ref_sys having columns srid , auth_name, auth_srid, srtext, and proj4text. SELECT * FROM spatial_ref_sys WHERE srtext LIKE '%\ /%'; Sometimes these ticks are very useful for searching special characters in a database.

Does PostgreSQL support Unicode?

One of the interesting features of PostgreSQL database is the ability to handle Unicode characters. In SQL Server, to store non-English characters, we need to use NVARCHAR or NCAHR data type. In PostgreSQL, the varchar data type itself will store both English and non-English characters.

How do you change character type in PostgreSQL?

PostgreSQL change column type statement First, specify the name of the table to which the column you want to change after the ALTER TABLE keywords. Second, specify the name of the column that you want to change the data type after the ALTER COLUMN clause.


1 Answers

To see otherwise invisible Unicode in a postgress table, you'll want to use "encode" and "escape" both. And just for fun, the escape function requires a cast to type bytea. Putting it all together:

# CREATE TABLE xxx_test (foo text);
# INSERT INTO xxx_test (foo) values (E'Invis\u200eble €');

# SELECT foo from xxx_test;
Invis‎ble €
# SELECT encode(foo::bytea, 'escape') FROM xxx_test;
Invis\342\200\216ble \342\202\254

# DROP TABLE xxx_test;
like image 197
Bryce Avatar answered Oct 13 '22 15:10

Bryce