Thread: Select Command

Select Command

From
Bob Pawley
Date:
I have a column with data structured as follows.
 
32TT - 0002
32LT- 0004
32PT-0005
 
Is there a way of selecting all of the rows containing LT in that column??
 
 
I have attempted variations of ' *LT* ' with out success.
 
Bob Pawley

Re: Select Command

From
Alvaro Herrera
Date:
Bob Pawley wrote:
> I have a column with data structured as follows.
>
> 32TT - 0002
> 32LT- 0004
> 32PT-0005
>
> Is there a way of selecting all of the rows containing LT in that column??
>
>
> I have attempted variations of ' *LT* ' with out success.

LIKE '%LT%' perhaps?

Or ~ 'LT' (unanchored regex)

--
Alvaro Herrera       Valdivia, Chile   ICBM: S 39º 49' 18.1", W 73º 13' 56.4"
"El número de instalaciones de UNIX se ha elevado a 10,
y se espera que este número aumente" (UPM, 1972)

Re: Select Command

From
Adrian Klaver
Date:
On Sunday 21 October 2007 2:32 pm, Bob Pawley wrote:
> I have a column with data structured as follows.
>
> 32TT - 0002
> 32LT- 0004
> 32PT-0005
>
> Is there a way of selecting all of the rows containing LT in that column??
>
>
> I have attempted variations of ' *LT* ' with out success.
>
> Bob Pawley

select col where col LIKE '%LT%';

See also:
http://www.postgresql.org/docs/8.2/interactive/functions-matching.html#FUNCTIONS-LIKE
--
Adrian Klaver
aklaver@comcast.net

Re: Select Command

From
Richard Broersma Jr
Date:
--- On Sun, 10/21/07, Adrian Klaver <aklaver@comcast.net> wrote:
> > I have a column with data structured as follows.
> >
> > 32TT - 0002
> > 32LT- 0004
> > 32PT-0005
> >
> > Is there a way of selecting all of the rows containing
> LT in that column??
> >
> > I have attempted variations of ' *LT* ' with
> out success.

I set up my table structure a little differently:

CREATE TABLE loops (
 area  INTEGER CHECK( AREA BETWEEN 1 AND 99),
 process_code VARCHAR(1)  CHECK ( process_code ~ [A-Z]),
 loop_nbr INTEGER CHECK( loop_nbr BETWEEN 1 AND 9999),
 suffix VARCHAR(1) CHECK ( suffix ~ [A-Z] ),
 loop_work_scope VARCHAR CHECK ( loop_work_scope IN ( 'NEW','REUSE','DEMO'),
PRIMARY KEY ( area, process_code, loop_nbr, suffix, loop_work_scope)
);

CREATE TABLE tags (
  area  INTEGER CHECK( AREA BETWEEN 1 AND 99),
 process_code VARCHAR(1)  CHECK ( process_code ~ [A-Z]),
 loop_nbr INTEGER CHECK( loop_nbr BETWEEN 1 AND 9999),
 suffix VARCHAR(1) CHECK ( suffix ~ [A-Z] ),
 loop_work_scope VARCHAR CHECK ( loop_work_scope IN ( 'NEW','REUSE','DEMO'),
Foriegn KEY ( area, process_code, loop_nbr, suffix, work_scope)
REFERENCES ( Loops.area, Loops.process_code, Loops, Loop_nbr, Loops_suffix, Loops.work_scope ),
 Instrument_code VARCHAR(4),
 Instrument_suffix varchar(1) check ( suffix ~ [A-Z])
 Instrument_work_scope varchar check (insturment_work_scope in ( 'NEW','REUSE','DEMO'),
Primary KEY ( area, Instrument_code, loop_nbr, instrument_suffix, Instrument_work_scope ) );

SELECT area || insturment_code || to_char( loop_nbr, '0000' ) || instrument_suffix AS tag
  FROM Tags
 WHERE instrument_code = 'LT'
     AND instrument_work_scope = 'NEW';