Question

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'
Was it helpful?

Solution

Use the dedicated characters ® or ™ as trademark signs.

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

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. I would generally discourage to use any of these except the common ¹ ² ³ . You would normally use formatting to achieve a superscript effect.

For instance, 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', 'ᴬᴮᴰᴱᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾᴿᵀᵁ');

OTHER TIPS

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

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).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top