Select Command

Started by Bob Pawleyover 18 years ago4 messagesgeneral
Jump to latest
#1Bob Pawley
rjpawley@shaw.ca

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

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Bob Pawley (#1)
Re: Select Command

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)

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Bob Pawley (#1)
Re: Select Command

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

#4Richard Broersma Jr
rabroersma@yahoo.com
In reply to: Adrian Klaver (#3)
Re: Select Command
--- 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';