pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed' escape
9+ messages / 6 participants
[nested] [flat]
* ' escape
@ 1998-12-07 15:31 Fabio Mancinelli <mancinel@univaq.it>
0 siblings, 2 replies; 9+ messages in thread
From: Fabio Mancinelli @ 1998-12-07 15:31 UTC (permalink / raw)
To: pgsql-sql
Hello all
I have a question. When I create a table I cannot use any escape to put a
' character in the default field definition.
CREATE TABLE Test (name varchar(128) default 'Something with '' into');
Fails. I've tried also other alternatives :
default "Something with ' into"
default "Something with '' into"
default 'Something with \' into'
default 'Something with \27 into'
default 'Something with \0x27 into'
Everything fails.
How can I set a default with a string containing a ' ?
Thank you all.
Bye
----------------------------------------------------------------------------
Greetings from Fabio Mancinelli E-Mail : mancinel@univaq.it
Computer Science Student xenon@olografix.org
University of L'Aquila WWW : http://univaq.it/~mancinel
(PGP Public Key available) http://www.olografix.org/xenon
A.L.U. Member
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [SQL] ' escape
@ 1998-12-07 16:04 Herouth Maoz <herouth@oumail.openu.ac.il>
parent: Fabio Mancinelli <mancinel@univaq.it>
1 sibling, 1 reply; 9+ messages in thread
From: Herouth Maoz @ 1998-12-07 16:04 UTC (permalink / raw)
To: Fabio Mancinelli <mancinel@univaq.it>; +Cc: pgsql-sql
At 17:31 +0200 on 7/12/98, Fabio Mancinelli wrote:
> I have a question. When I create a table I cannot use any escape to put a
> ' character in the default field definition.
>
> CREATE TABLE Test (name varchar(128) default 'Something with '' into');
>
> Fails. I've tried also other alternatives :
> default "Something with ' into"
> default "Something with '' into"
> default 'Something with \' into'
> default 'Something with \27 into'
> default 'Something with \0x27 into'
>
> Everything fails.
Interesting bug.
As a workaround, if you really need that default value, define a simple SQL
function which returns it:
testing=> CREATE FUNCTION specialValue() RETURNS varchar
testing-> AS 'SELECT ''a value with '''' in it''::varchar'
testing-> LANGUAGE 'sql';
CREATE
testing=> SELECT specialValue();
specialvalue
--------------------
a value with ' in it
(1 row)
Now define your table. Here is an example:
testing=> CREATE TABLE test6 (
testing-> id int,
testing-> name varchar(128) DEFAULT specialValue()
testing-> );
CREATE
testing=> INSERT INTO test6 (id) values (1);
INSERT 932640 1
testing=> SELECT * FROM test6;
id|name
--+--------------------
1|a value with ' in it
(1 row)
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [SQL] ' escape
@ 1998-12-07 21:10 Jan Wieck <jwieck@debis.com>
parent: Herouth Maoz <herouth@oumail.openu.ac.il>
0 siblings, 1 reply; 9+ messages in thread
From: jwieck@debis.com @ 1998-12-07 21:10 UTC (permalink / raw)
To: herouth@oumail.openu.ac.il; +Cc: mancinel@univaq.it; pgsql-sql
> > CREATE TABLE Test (name varchar(128) default 'Something with '' into');
> >
> > Fails. I've tried also other alternatives :
> > default "Something with ' into"
> > default "Something with '' into"
> > default 'Something with \' into'
> > default 'Something with \27 into'
> > default 'Something with \0x27 into'
> >
> > Everything fails.
>
> Interesting bug.
>
> As a workaround, if you really need that default value, define a simple SQL
> function which returns it:
Hmmm - bug or feature - dunno. But telling
... DEFAULT 'Something with '''' into' ...
works pretty good and as I expected it, results in one single
quoute.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [SQL] ' escape
@ 1998-12-07 22:59 Bruce Momjian <maillist@candle.pha.pa.us>
parent: Jan Wieck <jwieck@debis.com>
0 siblings, 2 replies; 9+ messages in thread
From: Bruce Momjian @ 1998-12-07 22:59 UTC (permalink / raw)
To: jwieck@debis.com; +Cc: herouth@oumail.openu.ac.il; mancinel@univaq.it; pgsql-sql
> > > CREATE TABLE Test (name varchar(128) default 'Something with '' into');
> > >
> > > Fails. I've tried also other alternatives :
> > > default "Something with ' into"
> > > default "Something with '' into"
> > > default 'Something with \' into'
> > > default 'Something with \27 into'
> > > default 'Something with \0x27 into'
> > >
> > > Everything fails.
> >
> > Interesting bug.
> >
> > As a workaround, if you really need that default value, define a simple SQL
> > function which returns it:
>
> Hmmm - bug or feature - dunno. But telling
>
> ... DEFAULT 'Something with '''' into' ...
>
> works pretty good and as I expected it, results in one single
> quoute.
I see the problem here:
test=> create table test33 (a int,x char(10) default 'x\'y');
ERROR: parser: parse error at or near "y"
--
Bruce Momjian | http://www.op.net/~candle
maillist@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [SQL] ' escape
@ 1998-12-08 09:27 Jan Wieck <jwieck@debis.com>
parent: Bruce Momjian <maillist@candle.pha.pa.us>
1 sibling, 0 replies; 9+ messages in thread
From: jwieck@debis.com @ 1998-12-08 09:27 UTC (permalink / raw)
To: maillist@candle.pha.pa.us; +Cc: jwieck@debis.com; herouth@oumail.openu.ac.il; mancinel@univaq.it; pgsql-sql
> > Hmmm - bug or feature - dunno. But telling
> >
> > ... DEFAULT 'Something with '''' into' ...
> >
> > works pretty good and as I expected it, results in one single
> > quoute.
>
> I see the problem here:
>
> test=> create table test33 (a int,x char(10) default 'x\'y');
> ERROR: parser: parse error at or near "y"
But
create table ... default 'x\'\'y');
does. Whenever something around quotes doesn't work, I first
try to double them.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [SQL] ' escape
@ 1998-12-08 09:45 Herouth Maoz <herouth@oumail.openu.ac.il>
parent: Bruce Momjian <maillist@candle.pha.pa.us>
1 sibling, 0 replies; 9+ messages in thread
From: Herouth Maoz @ 1998-12-08 09:45 UTC (permalink / raw)
To: pgsql-sql
At 11:27 +0200 on 8/12/98, Jan Wieck wrote:
>
> But
>
> create table ... default 'x\'\'y');
>
> does. Whenever something around quotes doesn't work, I first
> try to double them.
Nevertheless, it is a bug. You should double your quotes when they are
inside other quotes. When surrounded by doubled quotes, you have to
quadruple them. Or to escape them and escape the escapes. The following
also works:
testing=> CREATE TABLE test1
testing-> (
testing-> id int,
testing-> name varchar(128) default 'something with \\'' in it'
testing-> );
But it shouldn't, because it is only surrounded by single unescaped quotes.
If this string is used in any other context, it will have a single slash
and a single quote in it. Something is amiss.
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [SQL] ' escape
@ 1998-12-13 04:33 Bruce Momjian <maillist@candle.pha.pa.us>
parent: Fabio Mancinelli <mancinel@univaq.it>
1 sibling, 0 replies; 9+ messages in thread
From: Bruce Momjian @ 1998-12-13 04:33 UTC (permalink / raw)
To: mancinel@univaq.it; +Cc: pgsql-sql
>
> Hello all
>
> I have a question. When I create a table I cannot use any escape to put a
> ' character in the default field definition.
>
> CREATE TABLE Test (name varchar(128) default 'Something with '' into');
>
> Fails. I've tried also other alternatives :
> default "Something with ' into"
> default "Something with '' into"
> default 'Something with \' into'
> default 'Something with \27 into'
> default 'Something with \0x27 into'
>
> Everything fails.
>
> How can I set a default with a string containing a ' ?
>
> Thank you all.
Added to TODO:
* DEFAULT handles single quotes in value by requiring too many quotes
--
Bruce Momjian | http://www.op.net/~candle
maillist@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 9+ messages in thread
* % escape
@ 2000-08-15 19:02 Jie Liang <jliang@ipinc.com>
0 siblings, 1 reply; 9+ messages in thread
From: Jie Liang @ 2000-08-15 19:02 UTC (permalink / raw)
To: pgsql-sql
Hi,there,
Is anybody know how I can escape % or ' (my column contains % or ' )
in my text field.
select mystring from textbook where mystring like .....
--
Jie LIANG
Internet Products Inc.
10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873
jliang@ipinc.com
www.ipinc.com
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: % escape
@ 2000-08-15 19:37 Jesus Aneiros <aneiros@jagua.cfg.sld.cu>
parent: Jie Liang <jliang@ipinc.com>
0 siblings, 0 replies; 9+ messages in thread
From: Jesus Aneiros @ 2000-08-15 19:37 UTC (permalink / raw)
To: Jie Liang <jliang@ipinc.com>; +Cc: pgsql-sql
To escape % use \\% as in '50\\%', to escape ' use '' as in 'o''conell',
retrieves o'conell
Regards.
--
Jesus Aneiros Sosa
mailto:aneiros@jagua.cfg.sld.cu
http://jagua.cfg.sld.cu/~aneiros
On Tue, 15 Aug 2000, Jie Liang wrote:
> Hi,there,
>
> Is anybody know how I can escape % or ' (my column contains % or ' )
> in my text field.
>
> select mystring from textbook where mystring like .....
>
> --
> Jie LIANG
>
> Internet Products Inc.
>
> 10350 Science Center Drive
> Suite 100, San Diego, CA 92121
> Office:(858)320-4873
>
> jliang@ipinc.com
> www.ipinc.com
>
>
>
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2000-08-15 19:37 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-12-07 15:31 ' escape Fabio Mancinelli <mancinel@univaq.it>
1998-12-07 16:04 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1998-12-07 21:10 ` Jan Wieck <jwieck@debis.com>
1998-12-07 22:59 ` Bruce Momjian <maillist@candle.pha.pa.us>
1998-12-08 09:27 ` Jan Wieck <jwieck@debis.com>
1998-12-08 09:45 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1998-12-13 04:33 ` Bruce Momjian <maillist@candle.pha.pa.us>
2000-08-15 19:02 % escape Jie Liang <jliang@ipinc.com>
2000-08-15 19:37 ` Re: % escape Jesus Aneiros <aneiros@jagua.cfg.sld.cu>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox