> -----Original Message-----
> From: Tim Harsch [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 09, 2001 10:33 AM
> To: Ronald J Kimball
> Cc: M.W. Koskamp; Thomas A. Lowery; [EMAIL PROTECTED]
> Subject: RE: Checking for the existence of a certain row.
> 
> 
> 
> 
> > -----Original Message-----
> > From: Ronald J Kimball [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, July 09, 2001 6:33 AM
> > To: Tim Harsch
> > Cc: M.W. Koskamp; Thomas A. Lowery; [EMAIL PROTECTED]
> > Subject: Re: Checking for the existence of a certain row.
> >
> >
> > On Sun, Jul 08, 2001 at 12:52:45PM -0700, Tim Harsch wrote:
> > > but, does this (Sybase specific) query:
> > > select 1 where exists
> > > ( select * from some_table where some_column = 'some_value')
> in order to return a result.  So, now for the next question 
> how about the
> portability of this?  Is exist available in all the major 
> RDMS'?

If you're worried about portability, then just fetch the first
row, and finish the cursor:

my $sql = 'select 1 from some_table where some_column = ?';
my $sth = $dbh->prepare($sql);
$sth->execute($some_value);
my ($exists) = $sth->fetchrow_array;
$sth->finish;

The only inefficiency of this method might be if the database caches the
first N results, but otherwise this is as good as it gets. Its all sort
of ugly, so I'd probably put it off in some function.

Cheers,
Douglas Wilson

Reply via email to