Home > Postgresql - SQL, Server > How escape single quote ‘ in postgresql

How escape single quote ‘ in postgresql

To escape single quote in SQL Server and in PostgreSQL doubling them up ‘ as showed in examples below. It’s useful with SQL insert and update command:

Escape with the backslash \‘ is not prefereable  \’.

It’s possible to use dollar-quote string $ PostgreSQL: Documentation: 9.3: Lexical Structure:   ‘escape ” dollar-quote test ””’   ->  $$escape ‘ dollar-quote test ”$$  -> $token$escape ‘ dollar-quote test ”$token$

1) dubling up single quote ‘

INSERT INTO _aquery ( itemid, tcontent, title ) 
 VALUES ( 8503, SELECT * FROM information_schema.tables WHERE table_schema=''public'' and table_type=''BASE TABLE''', 'Show tables view sequences...' ) ;

Result:

itemid | tcontent	                                                                               | title
8502	 SELECT * FROM information_schema.tables WHERE table_schema='public' and table_type=BASE TABLE	 Show tables view sequences ...

1)

2)

INSERT INTO _aquery ( itemid, tcontent, title ) 
 VALUES (  8505, 
'SELECT n.nspname as "Schema",
       c.relname as "Name",
       CASE c.relkind WHEN ''r'' THEN ''table'' WHEN ''v'' THEN ''view'' WHEN ''i'' THEN ''index'' WHEN ''S'' THEN ''sequence'' WHEN ''s'' THEN ''special'' END as "Type",
      pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
  WHERE c.relkind IN (''r'','''')
  AND n.nspname <> ''pg_catalog''
  AND n.nspname <> ''information_schema''
  AND n.nspname !~ ''^pg_toast''
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;', 
'Show tables view sequences...' ) ;

Mysql use backslash \ to escape signle quote \

42 O\‘Connor Street

Risorse:

plpgsql 
Advertisements
  1. Non c'è ancora nessun commento.
  1. No trackbacks yet.

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger hanno fatto clic su Mi Piace per questo: