Re: Escaping `psql --variable` - Mailing list pgsql-general

From Jeff Davis
Subject Re: Escaping `psql --variable`
Date
Msg-id 1338337189.28651.25.camel@sussancws0025
Whole thread Raw
In response to Escaping `psql --variable`  (Alan Gutierrez <alan@prettyrobots.com>)
Responses Re: Escaping `psql --variable`
List pgsql-general
On Tue, 2012-05-29 at 18:32 -0400, Alan Gutierrez wrote:
> Surprised that this works:
>
>      echo ":foo" | psql --variable foo="SELECT 1 AS FOO;"  template1
>
> Why doesn't `psql` escape parameters passed in through `--variable`. When I use
> a library in other languages, they will escape the variable.
>
> How do I use `psql` from `bash` so that it will escape variables and thwart SQL
> injection?

http://www.postgresql.org/docs/9.1/static/app-psql.html#APP-PSQL-VARIABLES

In particular, look at the section on SQL Interpolation. Hopefully that
answers your question.

Regards,
    Jeff Davis



pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Re: Updateable Views or Synonyms.
Next
From: Craig Ringer
Date:
Subject: Re: Export and import from one postgres server to another