Re: print/return only the first X chars of a varchar column?

From: kalyan s <kalyans(at)huawei(dot)com>
To: 'Kevin Kempter' <kevink(at)consistentstate(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: print/return only the first X chars of a varchar column?
Date: 2009-09-03 04:10:40
Message-ID: 00d101ca2c4c$81be9d10$2001120a@china.huawei.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I think you can use the overlay function to do this.

http://www.postgresql.org/docs/current/static/functions-string.html

create table t1 (f char(10));
insert into t1 values ('abcdefg'),('hijklmno');
-- the below cmd will display only the first 2 characters of f.
-- if you want trim the spaces :) after this.
select overlay(f placing ' ' from 3 to 10);

Regards
kalyan

****************************************************************************
***********
This e-mail and attachments contain confidential information from HUAWEI,
which is intended only for the person or entity whose address is listed
above. Any use of the information contained herein in any way (including,
but not limited to, total or partial disclosure, reproduction, or
dissemination) by persons other than the intended recipient's) is
prohibited. If you receive this e-mail in error, please notify the sender by
phone or email immediately and delete it!

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Kevin Kempter
Sent: Monday, August 31, 2009 8:19 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] print/return only the first X chars of a varchar column?

Hi all;

I'm selecting from a table that has a varchar(1000) but I only want to
display
the firs 20 characters. Looked at the string functions in the docs but
nothing
jumped out...

Suggestions?

Thanks in advance

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adam Rich 2009-09-03 04:44:20 Re: Audit Trigger puzzler
Previous Message David Fetter 2009-09-03 01:11:19 Re: Add a serial column to a table based on a sort clause