PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at peppler dot org>
Subject: Re: Probably Trivial: Finding Largest Primary Key used in Table
Date: Jul 10 2005 12:17PM

On Sat, 2005-07-09 at 23:27 +0700, Jay Listo wrote:
> BTW, how do I do this in Perl using DBI and DBD::Sybase
> 
> I tried...
> 
> my $maxsth = $dbh->primary_key_info(undef, $dbuser, 'TABLE_NAME');
>   die "Unable to prepare SELECT MAX Key statement $DBI::errstr"
>     unless $maxsth;
> 
>   $getMaxKey = $maxsth->fetchall_arrayref
>        || die "Couldn't get the MAX KEY $DBI::errstr";
> 
> ....but $getMaxKey is not yet the value from "select max(keycol) from 
> TABLE_NAME"


primary_key_info() will give you the PK column(s) (IIRC). It doesn't
give you the current highest value.
You need to take the data returned here and build the appropriate select
statement to get the data you're looking for.

Michael
-- 
Michael Peppler  -  mpeppler@peppler.org  -  http://www.peppler.org/
Sybase DBA/Developer
Sybase on Linux FAQ: http://www.peppler.org/FAQ/linux.html