Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using <code>EXECUTE ... USING</code> with the <code>format()</code> function and its format specifiers will make your code much safer, simpler, easier to read and probably faster.</p> <hr> <p><strong>SQL INJECTION WARNING</strong>: If you ever accept <code>source_geom</code> or <code>target_geom</code> from the end user, your code is potentially vulnerable to <a href="http://bobby-tables.com/postgresql.html" rel="noreferrer">SQL injection</a>. It is important to use parameterized statements (like <code>EXECUTE ... USING</code>) or failing that, paranoid quoting to prevent SQL injection attacks. Even if you don't think your function takes user input you should still harden it against SQL injection, because you don't know how your app will evolve.</p> <hr> <p>If you're on a newer PostgreSQL with the <a href="http://www.postgresql.org/docs/current/static/functions-string.html" rel="noreferrer"><code>format</code> function</a> your code can be significantly simplified into:</p> <pre><code>EXECUTE format('update %I SET source = %L, target = %L WHERE %I = %L', geom_table, source_geom, target_geom, gid_cname, _r.id); </code></pre> <p>... which handles identifier (<code>%I</code>) and literal (<code>%L</code>) quoting for you using format specifiers so you don't have to write all that awful <code>||</code> concatenation and <code>quote_literal</code>/<code>quote_ident</code> stuff.</p> <p>Then, as per <a href="http://www.postgresql.org/docs/9.1/static/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE" rel="noreferrer">the documentation on <code>EXECUTE ... USING</code></a> you can further refine the query into:</p> <pre><code>EXECUTE format( 'update %I SET source = $1, target = $2 WHERE %I = $3', geom_table, gid_cname ) USING source_geom, target_geom, _r.id; </code></pre> <p>which turns the query into a parameterised statement, clearly separating parameters from identifiers and reducing string processing costs for a more efficient query.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload