varchar data type question
Posted in 2017
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Data Types & Schema Design
HI, A customer use ESQL/C to write the application, they want to change some data type from char to varchar, the customer want to know whether the running result will be changed ? What's the internal difference between char and varchar data type with ESQL/C? thanks for your time.
From the esql/c side there is no difference between a char and a varchar. You write the esql/c program with the data being defined as a char[x+1] where 'x' is the max size that the varchar is defined to be. Of course the "+1" is to provide space for the null terminator. When the data is moved from the database to/from the esql/c program, it will automatically converted into the target definition. Madison Pruet Retired and Loving it On Thursday, July 13, 2017 8:47 AM, CHUAN LU <luchuan@cn.ibm.com> wrote: HI, A customer use ESQL/C to write the application, they want to change some data type from char to varchar, the customer want to know whether the running result will be changed ? What's the internal difference between char and varchar data type with ESQL/C? thanks for your time. ******************************************************************************* Forum Note: Use "Reply" to post a response in the discussion forum.
On Thu, Jul 13, 2017 at 7:46 AM, CHUAN LU <luchuan@cn.ibm.com> wrote: > A customer use > âsâ > ESQL/C to write the application > â. They want to change some data > type > âsâ > from char to varchar, > âand â > the customer want > âsâ > to know whether the running > result will be changed? > âIt depends in part on how the ESQL/C is written. However, if it uses the CHAR data type (rather than say the string data type), then it is possible that you'll get blank padding on the stringsâ, which moots one of the main benefits of using VARCHAR. OTOH, it will continue to work without recompilation. > What's the internal difference between char and varchar data type with > ESQL/C? > âPrimarily that SQL and ESQL/C don't blank pad VARCHAR data. On disk, there's a byte stored for the length of the VARCHAR; that doesn't translate to the in-memory representation which is essentially the same as CHAR. â -- Jonathan Leffler <jonathan.leffler@gmail.com> #include <disclaimer.h> Guardian of DBD::Informix - v2015.1101 - http://dbi.perl.org "Blessed are we who can laugh at ourselves, for we shall never cease to be amused."
What is the reason to change a char for a varchar? If the column(s) are indexed be careful with the change... I assume the only valid reason for the change would be to save some space... but that comes with a cost, specially if the data is indexed. Regards On Thu, Jul 13, 2017 at 3:46 PM, CHUAN LU <luchuan@cn.ibm.com> wrote: > HI, > > A customer use ESQL/C to write the application, they want to change some > data > type from char to varchar, the customer want to know whether the running > result will be changed ? > > What's the internal difference between char and varchar data type with > ESQL/C? > > thanks for your time. > > > ************************************************************ > ******************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > -- Fernando Nunes Portugal http://informix-technology.blogspot.com My email works... but I don't check it frequently...