user6770216
user6770216

Reputation: 1

Difference between return value of a funciton

What will be the result of quote_ident(table_name::text) and what is the difference if we pass it rather than table in a pipeline statement? For e.g is there difference between

CREATE TRIGGER audit_trigger_stm AFTER ' || stm_targets || ' ON ' || quote_ident(table_name::text) ...

and this

CREATE TRIGGER audit_trigger_stm AFTER ' || stm_targets || ' ON ' || table_name ... 

Upvotes: 0

Views: 37

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247123

The difference is that without using quote_ident your composed statement becomes invalid if table_name contains spaces, double quotes or other niceties (or is a reserved SQL keyword).

Moreover, using quote_ident saves you from SQL injection if table_name comes from an untrusted source.

Upvotes: 2

Related Questions