Unix Technical Forum

BUG #3428: plperl spi_exec_prepared char length always unity

This is a discussion on BUG #3428: plperl spi_exec_prepared char length always unity within the pgsql Bugs forums, part of the PostgreSQL category; --> The following bug has been logged online: Bug reference: 3428 Logged by: Matt Taylor Email address: matt@lindenelevator.com PostgreSQL version: ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 11:56 AM
Matt Taylor
 
Posts: n/a
Default BUG #3428: plperl spi_exec_prepared char length always unity


The following bug has been logged online:

Bug reference: 3428
Logged by: Matt Taylor
Email address: matt@lindenelevator.com
PostgreSQL version: 8.2.4
Operating system: Gentoo
Description: plperl spi_exec_prepared char length always unity
Details:

The spi_prepare and spi_exec_prepared doesn't seem to properly handle fixed
character types. Only the first character of a string is passed to the
database.

Is this behavior related to the following statement from the manual?

PostgreSQL 8.2.4 Documentation
Chapter 8. Data Types
8.3. Character Types

The type "char" (note the quotes) is different from char(1) in that it only
uses one byte of storage. It is internally used in the system catalogs as a
poor-man's enumeration type.

Matt Taylor


The following code should recreate the problem:

create table bug_demo_table ( xx char(2) );
insert into bug_demo_table ( xx ) values ( 'AB' );

CREATE FUNCTION bug_demo() RETURNS INTEGER AS $$

my $sql = 'insert into bug_demo_table ( xx ) values ( $1 );' ;

my $sth = spi_prepare( $sql, 'char' );
spi_exec_prepared( $sth, 'CD' ); # broken

my $sth = spi_prepare( $sql, 'text' );
spi_exec_prepared( $sth, 'EF' ); # works

my $sth = spi_prepare( $sql, 'varchar' );
spi_exec_prepared( $sth, 'GH' ); # works

return 1;

$$ LANGUAGE 'plperlu';

select bug_demo();
select * from bug_demo_table;

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 11:56 AM
Tom Lane
 
Posts: n/a
Default Re: BUG #3428: plperl spi_exec_prepared char length always unity

"Matt Taylor" <matt@lindenelevator.com> writes:
> The spi_prepare and spi_exec_prepared doesn't seem to properly handle fixed
> character types. Only the first character of a string is passed to the
> database.


IIRC, "char" means "char(1)" by default, so I'm unconvinced that this
behavior is a bug.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 11:56 AM
Matt Taylor
 
Posts: n/a
Default Re: BUG #3428: plperl spi_exec_prepared char length alwaysunity

On Thu, 2007-07-05 at 00:13 -0400, Tom Lane wrote:
> "Matt Taylor" <matt@lindenelevator.com> writes:
> > The spi_prepare and spi_exec_prepared doesn't seem to properly handle fixed
> > character types. Only the first character of a string is passed to the
> > database.

>
> IIRC, "char" means "char(1)" by default, so I'm unconvinced that this
> behavior is a bug.
>
> regards, tom lane
>



Since 'character' is not accepted as a valid type by spi_prepare, is
this bug a duplicate of BUG #2917? Maybe I am just doing this wrong,
the documentation is sparse.

Matt




---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 11:57 AM
Tom Lane
 
Posts: n/a
Default Re: BUG #3428: plperl spi_exec_prepared char length always unity

Matt Taylor <matt@lindenelevator.com> writes:
> On Thu, 2007-07-05 at 00:13 -0400, Tom Lane wrote:
>> IIRC, "char" means "char(1)" by default, so I'm unconvinced that this
>> behavior is a bug.


> Since 'character' is not accepted as a valid type by spi_prepare, is
> this bug a duplicate of BUG #2917? Maybe I am just doing this wrong,
> the documentation is sparse.


Oh, duh, I should have thought harder. Yeah, in 8.2 you will get the
internal 1-byte-char datatype, not bpchar which is what spi_prepare
will interpret this as meaning in 8.3 and beyond.

I'd suggest using "bpchar", or maybe better "varchar" (do you actually
want fixed-width char type??) for the time being.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:07 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com