Обсуждение: how to insert '\\' in postgres database using java

Поиск
Список
Период
Сортировка

how to insert '\\' in postgres database using java

От
ketan shah
Дата:
Hi,
  All, 
My name is ketan, i have problem in postgres db insert..
 Here is my problem.
i have created table like..
1)  Create table tab1(usr_id varchar(15), usr_name varchar(20),usr_filename_pattern varchar(1024));
      insert table tab1 values('A','Mr. A','A\\d\\d\\d\\d');
     Record is successfully inserted But when i retrieve using java program..
      select * from tab1;
     The output is 'A',     'Mr. A',      'A\d\d\d\d'            (means it escapeing '\')
     Also when i update the record
     update tab1 set usr_name='Mr. B' where usr_id='A';
  
     and after succefully  updation when i try to retrieve record by
    select * from tab1;
   output is  'A','Mr. B', 'Adddd'    ; (means it escapeing '\'     again)
  
   My question :
    After updation  how i get
   'A', 'Mr. B', 'A\\d\\d\\d\\d'
  i.e. not escapeing '\\'.
  I am using postgres 7.4.6 and java 1.4.
pl. help me out...
 
Thanks in advanced..
ketan

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Re: how to insert '\\' in postgres database using java

От
Ropel
Дата:
If, as the name of the column suggests, the backslash is used for
pathnames, why don't you bypass the problem by using normal slash (I.E:
"path/to/my/file")? It works well
with new windows versions and, of course, unix-style pathnames....

Hope this helps, Roberto

ketan shah wrote:

> Hi,
>   All,
> My name is ketan, i have problem in postgres db insert..
>  Here is my problem.
> i have created table like..
> 1)  Create table tab1(usr_id varchar(15), usr_name
> varchar(20),usr_filename_pattern varchar(1024));
>       insert table tab1 values('A','Mr. A','A\\d\\d\\d\\d');
>      Record is successfully inserted But when i retrieve using java
> program..
>       select * from tab1;
>      The output is 'A',     'Mr. A',      'A\d\d\d\d'
> (means it escapeing '\')
>      Also when i update the record
>      update tab1 set usr_name='Mr. B' where usr_id='A';
>
>      and after succefully  updation when i try to retrieve record by
>     select * from tab1;
>    output is  'A','Mr. B', 'Adddd'    ; (means it escapeing '\'     again)
>
>    My question :
>     After updation  how i get
>    'A', 'Mr. B', 'A\\d\\d\\d\\d'
>   i.e. not escapeing '\\'.
>   I am using postgres 7.4.6 and java 1.4.
> pl. help me out...
>
> Thanks in advanced..
> ketan
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>



Re: how to insert '\\' in postgres database using java

От
Michael Glaesemann
Дата:
Hi Ketan,

On Jul 15, 2005, at 10:49 PM, ketan shah wrote:

>       My question :
>     After updation  how i get
>    'A', 'Mr. B', 'A\\d\\d\\d\\d'
>   i.e. not escapeing '\\'.
>   I am using postgres 7.4.6 and java 1.4.
> pl. help me out...

As you've noticed, the \ character is currently used in PostgreSQL as
an escape, so '\\' is recognized as one \. So if you want to insert \
\, you need to escape both \; i.e., '\\\\'

test=# select '\\';
?column?
----------
\
(1 row)

test=# select '\\\\';
?column?
----------
\\
(1 row)

test=# create table tab1 (
     usr_id varchar(15)
     , usr_name varchar(20)
     ,usr_filename_pattern varchar(1024)
     );
CREATE TABLE
test=# insert into tab1 (usr_id, usr_name, usr_filename_pattern)
     values ('A','Mr. A','A\\d\\d\\d\\d');
INSERT 82771 1
test=# insert into tab1 (usr_id, usr_name, usr_filename_pattern)
     values ('A','Mr. B','A\\\\d\\\\d\\\\d\\\\d');
INSERT 82772 1
test=# select * from tab1;
usr_id | usr_name | usr_filename_pattern
--------+----------+----------------------
A      | Mr. A    | A\d\d\d\d
A      | Mr. B    | A\\d\\d\\d\\d
(2 rows)

Is this what you're looking for?

As an aside, I find it very helpful to name the columns when I'm
inserting them. (INSERT INTO foo (bar, baz, bat) VALUES ... instead
of INSERT INTO foo VALUES ... )Then I don't have to remember exactly
which column order I used when creating the table.

Hope this helps.

Michael Glaesemann
grzm myrealbox com



Re: how to insert '\\' in postgres database using java

От
Michael Glaesemann
Дата:
Ketan,

Please reply to the list as well so others have the opportunity to
help you. And please don't top-post.

On Jul 16, 2005, at 12:31 AM, ketan shah wrote:
>
>  but if i update more then two times then it remove all '\';
>
>  and finally it returns 'Adddd'  or 'Bdddd'...
>
>  But i want 'A\\d\\d\\d\\d'  and 'B\\d\\d\\d\\d' after n number of
> updates.
>
>  i.e. no change in inserted value after n numbers of updates for
> that record.

If you don't change change the values of the usr_filename_pattern in
the update (in the SET clause), those values should not change.

test=# select * from tab1;
usr_id | usr_name | usr_filename_pattern
--------+----------+----------------------
A      | Mr. A    | A\d\d\d\d
A      | Mr. B    | A\\d\\d\\d\\d
(2 rows)

test=# update tab1 set usr_name = 'Mr. C' where usr_id = 'A';
UPDATE 2
test=# select * from tab1;
usr_id | usr_name | usr_filename_pattern
--------+----------+----------------------
A      | Mr. C    | A\d\d\d\d
A      | Mr. C    | A\\d\\d\\d\\d

I suspect there is some additional SQL code being executed by your
Java application. You may want to enable query logging and check the
PostgreSQL logs to see exactly what queries are being executed.

Michael Glaesemann
grzm myrealbox com


Re: how to insert '\\' in postgres database using java

От
Martijn van Oosterhout
Дата:
On Fri, Jul 15, 2005 at 04:20:52PM +0200, Ropel wrote:
> If, as the name of the column suggests, the backslash is used for
> pathnames, why don't you bypass the problem by using normal slash (I.E:
> "path/to/my/file")? It works well
> with new windows versions and, of course, unix-style pathnames....

This has worked since DOS 2.0. Just not on the command line because the
slash is the option indicator. But the C library and the OS always
accepted forward slashes...

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Вложения