Special superscript characters

7.9k Views Asked by At

How to insert string with super script characters in PostgreSQL?

I want to insert "TM" as power of string "RACH"? I tried the following query:

update contact SET name=E'RACH$^'TM where id='10782'
3

There are 3 best solutions below

1
On BEST ANSWER

Use the dedicated characters '®' or '™' as trademark signs.

UPDATE contact SET name = 'RACH™'  -- '™' not 'ᵀᴹ'
WHERE  id = '10782';

Some other characters (but not all!) have superscript variants in Unicode, but many fonts don't support these exotic code points and don't even include glyphs to represent them. Except for the common '¹ ² ³', I would rather use formatting to achieve a superscript effect.

Here on SO, you could use: demo superscript ABC
That's the output of <sup>demo superscript ABC</sup>
More info on the Wikipedia page on superscript characters.

If you need a mapping function use translate(). replace() in a loop would be very inefficient.

translate('TM', 'ABDEGHIJKLMNOPRTU', 'ᴬᴮᴰᴱᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾᴿᵀᵁ');
0
On

I don't know if it possible to convert symbols to supersripts without creating mapping function for that, but you can just write it manually:

update contact SET name='RACHᵀᴹ' where id='10782'

sql fiddle demo

Mapping function could be something like this:

create or replace function superscript(data text)
returns text
as
$$
declare
   ss text[];
   lt text[];
begin
   ss := '{ᴬ,ᴮ,ᴰ,ᴱ,ᴳ,ᴴ,ᴵ,ᴶ,ᴷ,ᴸ,ᴹ,ᴺ,ᴼ,ᴾ,ᴿ,ᵀ,ᵁ}';
   lt := '{A,B,D,E,G,H,I,J,K,L,M,N,O,P,R,T,U}';
   for i in 1..array_length(ss, 1)
   loop
       data := replace(data, lt[i], ss[i]);
   end loop;
   return data;
end;
$$
language plpgsql;

sql fiddle demo

0
On

In text editor like Word or LibreOffice Writer:

  • Insert the required special symbol using special menu section. Don't use upper index to format your number in case of degrees - just insert a special symbol.
  • Copy it to clipboard.
  • Paste into cell in your database manager (Intellij's Data Grip or other).