Re: the use of $$string$$

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: the use of $$string$$
Дата
Msg-id 1320729388.31945.7.camel@vanquo.pezone.net
обсуждение исходный текст
Ответ на Re: the use of $$string$$  (Richard Huxton <dev@archonet.com>)
Список pgsql-sql
On mån, 2011-11-07 at 08:44 +0000, Richard Huxton wrote:
> > myvarString = "long string that contains single quotes"
> > cusor.execute("insert into table (pkid, myfield) values (%s, $$%s
> $$)",(123,
> > myvarString))
> >
> > When I execute the above I'm seeing:
> > E'long string that contains single quotes' in the field.  When I do
> a "select
> > * from table"   I get E'long string that contains single quotes'.
> 
> OK, so it seems psycopg is quoting your strings for you (as you'd 
> expect). It's presumably turning your query into:
>      ... values (E'123', $$E'<long string>'$$)
> So - the $$ quoting is unnecessary here - just use the % placeholders.
> 
> Incidentally, should it be %s for the numeric argument?

Yes.




В списке pgsql-sql по дате отправления:

Предыдущее
От: Robins Tharakan
Дата:
Сообщение: Re: GROUP and ORDER BY
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: Number timestamped rows