Re: Question - Query based on WHERE OR

From: Ragnar <gnari(at)hive(dot)is>
To: Mike Poe <trolling4dollars(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Question - Query based on WHERE OR
Date: 2007-01-12 22:32:19
Message-ID: 1168641139.19451.10.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On mið, 2007-01-10 at 17:38 -0800, Mike Poe wrote:
> I'm a rank newbie to Postgres & am having a hard time getting my arms
> around this.
>
> I'm trying to construct a query to be run in a PHP script. I have an
> HTML form were someone can enter either a last name or a social
> security number & then query the database based on what they entered.
>
> My query looks like this:
>
> SELECT foo, baz, bar FROM public.table WHERE lastname ~* '$lastname' OR
> ssn='$ssn'"
>
> I need to leave the last name a wildcard in case someone enters a
> partial name, lower case / upper case, etc.

note that you really should not be using values directly from
user input for $lastname and $ssn without doing some sanity
checks on them. consider for example the user submitting a
string containing a quote character.

most languages provide functions to make such input safe.

gnari

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2007-01-12 22:33:05 Re: Autovacuum Improvements
Previous Message Rob Tanner 2007-01-12 22:24:34 I've compiled and installed -- what next?