Armen Tsirunyan Armen Tsirunyan - 20 days ago 6
SQL Question

quine (self-producing) SQL query

This is a very interesting wiki article about programs that print their own source code without any access to physical source file (in the filesystem). Examples in the articles include C and Scheme quine programs (yeah, it appears they are called like that). I remember someone asking me long ago (about 5 years) whether I could write an SQL query that "returns itself". I had given it little thought back then (to be perfectly honest I hadn't given it any thought at all). But After reading this article I recalled that thing. Now I want to state that the person who asked that problem is not 100% credible in that it is pretty much possible he had no idea what he was talking about. But maybe it's possible? So, does anyone know if there exist quine SQL queries, whatever "return itself" may mean in that context. Thanks.

Answer

SQL Server version, from here:

SELECT REPLACE(REPLACE('SELECT REPLACE(REPLACE("$",CHAR(34),CHAR(39)),CHAR(36),"$") AS Quine',CHAR(34),CHAR(39)),CHAR(36),'SELECT REPLACE(REPLACE("$",CHAR(34),CHAR(39)),CHAR(36),"$") AS Quine') AS Quine

Comments