pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Beth Gatewood <bethg@mbt.washington.edu>
To: Francis Solomon <francis@stellison.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: trying to pattern match to a value contained in a column
Date: Thu, 07 Dec 2000 13:45:00 -0800
Message-ID: <3A3004DC.4FF7CB37@mbt.washington.edu> (raw)
References: <NEBBIFFPELJMCJAODNPKIEKHCDAA.francis@stellison.co.uk>

Hi Francis-

Thank you for your rapid and excellent response.

This makes perfect sense...unfortunately it isn't working...

I hope this isn't because I am using 6.3 (yes...I know it is very very
old but this is currently where the data is!)

here is the query:

select * from av34s1 where chromat ~~ ('%' || sample || '%');


ERROR:  parser: syntax error at or near "||"

I have also tried using LIKE....

samething..

NOW..
select * from av34s1 where chromat~sample;

ERROR:  There is no operator '~' for types 'bpchar' and 'bpchar'
        You will either have to retype this query using an explicit
cast,
        or you will have to define the operator using CREATE OPERATOR


Indeed...

Table    = av34s1
+----------------------------------+----------------------------------+-------+

|              Field               |              Type                |
Length|
+----------------------------------+----------------------------------+-------+

| contig                           | char()
|    10 |
| contig_pos                       | char()
|    10 |
| read_pos                         | char()
|    10 |
| chromat                          | char()
|    30 |
| sample                           | char()
|    30 |
| allele1                          | char()
|    10 |
| allele2                          | char()
|    10 |
| ref_pos                          | char()
|    10 |
| ref_sample                       | char()
|    10 |
| tag                              | char()
|    10 |
| source                           | char()
|    10 |
+----------------------------------+----------------------------------+-------+

Thanks for your response...

Beth


Francis Solomon wrote:

> Hi Beth,
>
> Try something like this ...
>
> Here's a simple table schema:
>
> CREATE TABLE abbrev (
>   abbr varchar(10),
>   long_name varchar(50),
>   primary key(abbr)
> );
>
> Throw in some random data:
>
> INSERT INTO abbrev VALUES ('fs', 'fsolomon');
> INSERT INTO abbrev VALUES ('bg', 'bgatewood');
> INSERT INTO abbrev VALUES ('junk', 'nomatch');
>
> Query the table:
>
> SELECT * FROM abbrev WHERE long_name~abbr;
>
> ... which yields these results:
>
>  abbr |  long_name
> ------+-----------
>  fs   | fsolomon
>  bg   | bgatewood
>
> Note that ~ does a case-sensitive regex match. If you really want a
> 'like' match, you could do this instead:
>
> SELECT * FROM abbrev where long_name~~('%' || abbr || '%');
>
> ... where '||' is the string-concatenation operator.
>
> Hope this helps
>
> Francis Solomon
>
> > -----Original Message-----
> > From: pgsql-sql-owner@postgresql.org
> > [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Beth Gatewood
> > Sent: 07 December 2000 21:06
> > To: pgsql-sql@postgresql.org
> > Subject: [SQL] trying to pattern match to a value contained
> > in a column
> >
> >
> > Hi-
> >
> > I can't figure out how to do this....
> >
> > I examine a table where I think that one attribute is an
> > abbreviation of
> > another attribute.
> >
> > So-If I had a table where I had LONG_NAME and ABBR as attributes.
> >
> > I want something like
> >
> > SELECT whatever FROM my_table WHERE long_name LIKE '%[the
> > value of ABBR
> > in that row]%';
> >
> >
> > Of course this doesn't work...
> >
> > Any thoughts?
> >
> > Thanks-
> > Beth
> >
> >
> >




view thread (8+ messages)  latest in thread

Message-ID: <3A3004DC.4FF7CB37@mbt.washington.edu>
Permalink:  ../3A3004DC.4FF7CB37@mbt.washington.edu/
Also on:    postgresql.org/message-id/3A3004DC.4FF7CB37@mbt.washington.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: bethg@mbt.washington.edu, francis@stellison.co.uk
  Subject: Re: trying to pattern match to a value contained in a column
  In-Reply-To: <3A3004DC.4FF7CB37@mbt.washington.edu>
  References: <NEBBIFFPELJMCJAODNPKIEKHCDAA.francis@stellison.co.uk> <3A3004DC.4FF7CB37@mbt.washington.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox