Thread: How to obtain the max length of a varchar(50) field.

How to obtain the max length of a varchar(50) field.

From
Mauro Ziliani
Date:
Hi all.
I'm working with Postgres 9.0 and wxWidgets.
I need to query the db about a field of a table.

The table T has a field varchar(50).

table: TAB0
customer: varchar(50)

How can I get the max size of the field?

The PQfsize function give me -1 because the field has dynamic size.

Can you help me?

Best regards
   MZ.

Re: How to obtain the max length of a varchar(50) field.

From
Simon Riggs
Date:
On Thu, May 5, 2011 at 9:50 AM, Mauro Ziliani <mauro@faresoftware.it> wrote:
> Hi all.
> I'm working with Postgres 9.0 and wxWidgets.
> I need to query the db about a field of a table.
>
> The table T has a field varchar(50).
>
> table: TAB0
> customer: varchar(50)
>
> How can I get the max size of the field?
>
> The PQfsize function give me -1 because the field has dynamic size.
>
> Can you help me?

Try PQfmod()

--
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Re: How to obtain the max length of a varchar(50) field.

From
Andreas Kretschmer
Date:
Mauro Ziliani <mauro@faresoftware.it> wrote:

> Hi all.
> I'm working with Postgres 9.0 and wxWidgets.
> I need to query the db about a field of a table.
>
> The table T has a field varchar(50).
>
> table: TAB0
> customer: varchar(50)
>
> How can I get the max size of the field?

select max(length(customer)) from tab0;



Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: How to obtain the max length of a varchar(50) field.

From
Mauro Ziliani
Date:
On 05/05/2011 11:03, Simon Riggs wrote:
> On Thu, May 5, 2011 at 9:50 AM, Mauro Ziliani<mauro@faresoftware.it>  wrote:
>> Hi all.
>> I'm working with Postgres 9.0 and wxWidgets.
>> I need to query the db about a field of a table.
>>
>> The table T has a field varchar(50).
>>
>> table: TAB0
>> customer: varchar(50)
>>
>> How can I get the max size of the field?
>>
>> The PQfsize function give me -1 because the field has dynamic size.
>>
>> Can you help me?
> Try PQfmod()
>
Ok I'll try it. Reading I skip this function.
Thank you.

MZ

Re: How to obtain the max length of a varchar(50) field.

From
Mauro Ziliani
Date:
On 05/05/2011 11:03, Andreas Kretschmer wrote:
> Mauro Ziliani<mauro@faresoftware.it>  wrote:
>
>> Hi all.
>> I'm working with Postgres 9.0 and wxWidgets.
>> I need to query the db about a field of a table.
>>
>> The table T has a field varchar(50).
>>
>> table: TAB0
>> customer: varchar(50)
>>
>> How can I get the max size of the field?
> select max(length(customer)) from tab0;
>
>
>
> Andreas
Thank you for the suggestion.
But I look a C function which access PGresult record.

This is usefull for an sql script.
Thank you very much.

MZ