[JDBC] Using char fields with 7.1.3 driver
I've found after using a CMP J2EE entity bean, along with the 7.1.3 jdbc driver, queries return the entire char field back while using char(), but varchar returns just the value of the field back. for example, create table test_table( id integer primary key not null, name varchar(255) ); vs. create table test_table( id integer primary key not null, name char(255) ); When returning the name value from the first table it looks something like this (single quotes are in just to show the entire field) 'Name' However, when using the second table this happens: 'Name ' notice the 249 characters of whitespace. I can easily get around this using .trim(), but I'm wondering if that should be in the jdbc driver itself (as I'll have to go through a bit of code looking for string values being returned). Or is this something in the database software itself that you can configure? Also, Is there a real Website for the postgres jdbc driver? http://jdbc.postgresql.org seems a little outdated. I wouldn't mind being able to grab the source for the driver and putting in this small fix myself. -Jeff ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send unregister YourEmailAddressHere to [EMAIL PROTECTED])
[Fwd: Re: [JDBC] Using char fields with 7.1.3 driver]
Hmm.. ok. Just I usually prefer using fixed field lengths as queries tend to be significantly faster. Also, you can use them in indexes. I find it strange that that would be the case... And it leads me to wonder how you would represent an ending space in a field, for example insert into names values(1,'This is a space'); for perhaps some sort of formatting or something otherwise. I'll try and find something in the postgres documentation to disable this then I guess. -Jeff Original Message Subject: Re: [JDBC] Using char fields with 7.1.3 driver From: David Wall [EMAIL PROTECTED] To: [EMAIL PROTECTED] I'm not a JDBC expert, but this is pretty much the way I'd expect it to work. If you a have fixed length field, then the field should return that many characters. The varchar implies it's variable length, so trailing spaces would then not be included. David ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]
Re: [JDBC] Using char fields with 7.1.3 driver]
Well, that's how it works in the postgres documentation... I could have sworn that I've never encountered this in other databases.. Must have a bad memory. Guess I'll just trim everything. -Jeff Hmm.. ok. Just I usually prefer using fixed field lengths as queries tend to be significantly faster. Also, you can use them in indexes. I find it strange that that would be the case... And it leads me to wonder how you would represent an ending space in a field, for example insert into names values(1,'This is a space'); for perhaps some sort of formatting or something otherwise. I'll try and find something in the postgres documentation to disable this then I guess. -Jeff Original Message Subject: Re: [JDBC] Using char fields with 7.1.3 driver From: David Wall [EMAIL PROTECTED] To: [EMAIL PROTECTED] I'm not a JDBC expert, but this is pretty much the way I'd expect it to work. If you a have fixed length field, then the field should return that many characters. The varchar implies it's variable length, so trailing spaces would then not be included. David ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly ---(end of broadcast)--- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED] ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [Fwd: Re: [JDBC] Using char fields with 7.1.3 driver]
[EMAIL PROTECTED] writes: Just I usually prefer using fixed field lengths as queries tend to be significantly faster. Also, you can use them in indexes. You are making assumptions based on other databases that are not relevant to Postgres. And it leads me to wonder how you would represent an ending space in a field, In varchar or text fields, trailing spaces are real data. In fixed-width char fields, trailing spaces are pads. AFAIK this is consistent with the SQL92 specification. regards, tom lane ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
Re: [JDBC] Using char fields with 7.1.3 driver
I'm not a JDBC expert, but this is pretty much the way I'd expect it to work. If you a have fixed length field, then the field should return that many characters. The varchar implies it's variable length, so trailing spaces would then not be included. David ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [JDBC] Using char fields with 7.1.3 driver
I can easily get around this using .trim(), but I'm wondering if that should be in the jdbc driver itself (as I'll have to go through a bit of code looking for string values being returned). char() is fixed length, varchar isn't. Or is this something in the database software itself that you can configure? Also, Is there a real Website for the postgres jdbc driver? http://jdbc.postgresql.org seems a little outdated. I wouldn't mind being able to grab the source for the driver and putting in this small fix myself. http://jdbc.fastcrypt.com -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup.| Drexel Hill, Pennsylvania 19026 ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster