True. That does sound like the best solution. But, how will the major
RDBMS' handle this? If they cache the first N, maybe up to available cache
memory, then the cache needs to be refilled again by other processes that
need it. Not wanting to get in to DB optimization techniques, but don't
want our query to be a bad citizen.
I guess the question is, how much work gets done by the server before DBI
finishes the cursor?
> -----Original Message-----
> From: Wilson, Doug [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 09, 2001 10:58 AM
> To: 'Tim Harsch'; 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: 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
>