0

I am using PostgreSQL and I need fields as strings not text. Here is the statement

select AutoNbr, 
       concat_ws(', ', Site_Street, Site_City, Site_Country, Site_PostCode) as cFullAddress , Order_Date 
from Porder

What I need is the cFullAddress to be a varchar not a text field.

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
sippytom
  • 27
  • 8

1 Answers1

0

According to documents:

If character varying is used without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension.

In addition, PostgreSQL provides the text type, which stores strings of any length. Although the type text is not in the SQL standard, several other SQL database management systems have it as well.

But you can cast it into varchar;

select AutoNbr, 
 concat_ws(', ', Site_Street, Site_City, Site_Country, Site_PostCode)::varchar as cFullAddress , Order_Date,
 CAST(concat_ws(', ', Site_Street, Site_City, Site_Country, Site_PostCode) as VARCHAR)
from Porder

Related link for using cast: type cast

Difference between text and varchar (character varying)

Community
  • 1
  • 1
light souls
  • 648
  • 1
  • 8
  • 17