  We present a flexible template-based photometric redshift estimation
framework, implemented in C#, that can be seamlessly integrated into a SQL
database (or DB) server and executed on-demand in SQL. The DB integration
eliminates the need to move large photometric datasets outside a database for
redshift estimation, and utilizes the computational capabilities of DB
hardware. The code is able to perform both maximum likelihood and Bayesian
estimation, and can handle inputs of variable photometric filter sets and
corresponding broad-band magnitudes. It is possible to take into account the
full covariance matrix between filters, and filter zero points can be
empirically calibrated using measurements with given redshifts. The list of
spectral templates and the prior can be specified flexibly, and the expensive
synthetic magnitude computations are done via lazy evaluation, coupled with a
caching of results. Parallel execution is fully supported. For large upcoming
photometric surveys such as the LSST, the ability to perform in-place photo-z
calculation would be a significant advantage. Also, the efficient handling of
variable filter sets is a necessity for heterogeneous databases, for example
the Hubble Source Catalog, and for cross-match services such as SkyQuery. We
illustrate the performance of our code on two reference photo-z estimation
testing datasets, and provide an analysis of execution time and scalability
with respect to different configurations. The code is available for download at
https://github.com/beckrob/Photo-z-SQL.
