Re: [CDBI] sql function as column
Oliver Jeeves <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Jason Bodnar wrote: > I have a table with just two columns - id int auto_increment and name > varchar(255). I'd like to have a third "virtual" column called code. The SQL > for retrieving all three columns would be: > > select id, name, conv(id,10,36) as code from table where name = ? > > conv is a (possibly mysql-only) function that converts the first argument from > the base second arg to base third arg. (In this case it converts the id from > base 10 to base 36). > > Is there a way to do this with CDBI? The first thing that comes to mind, is to do this with perl instead of SQL, simply because I can think how that would be achieved with CDBI. CDBI lets you have temporary columns (aren't stored; don't relate to an SQL column). You could then use a select trigger to populate this column whenever you retrieve a row from the database. Alternativly, could you setup a view in MySQL, and have your CDBI class use the view as its table. -Oli _______________________________________________ ClassDBI mailing list ClassDBI-Ra3b/[email protected] http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
signature.asc
(application/pgp-signature, 252 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFF0tNiSbWXajvTQ+URAiJeAJ9gAwn4qdoc7auYyYkDAuV8s8R5WQCgkJI4 YAydQaZYAgLvCkteXdM1KLM= =Tz1a -----END PGP SIGNATURE-----