1

Suppose you have a DB table like this:

Table t .... column_a integer column_b varchar(255) .... 

Now, I want to store a string that is composed by a list of names on t.column_b, with the following format (separated by commas):

Word A, Word B, Word C... 

The problem is, it might be the case that the string is larger than 255 characters and in my application logic I don't want to blindly trim to 255, but instead store the maximum number of words possible, eliminating the last word that exceeds the size. Also, I want to develop in such a way that if the column changes size, I don't want to change my application. Is it possible to write a SQL query that retrieves the declared size of a column? Or perhaps, I should use another column type?

If relevant, I am using Informix.

Thanks in advance.

1 Answer 1

1
  1. Informix truncates blindly at the limit unless your database is MODE ANSI.
  2. The DBI defines metadata attributes for columns and DBD::Informix implements them.

    For a statement handle, $sth, you can use:

    $sth->{PRECISION}->[0] 

    to get the precision (length) of the first column in the output.

See perldoc DBI under 'Statement Handle Attributes'.

If you need to know the type information for some column, write a SELECT statement, prepare it, then analyze the statement handle.

Because this is defined by DBI, you will get the same behaviour with any driver (DBD::YourDBMS).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.