7
\$\begingroup\$

Some of the site's questions rule that something must (or must not) be printed to the output. My question is, in the case of SQL, what really is the output?

The select command returns result-sets, which can be a 1x1 array of "string". The print command, as defined in a specific implementation (sql server), returns a string to the user.

So select 'Hello world!' and print 'Hello world!' are both valid commands that return the same string to the user, albeit in different places.

So, which of these are considered "printing" in terms of golf SE? Could it be both?

| |
\$\endgroup\$
  • 2
    \$\begingroup\$ I'd think either would be allowed, like how there's alert, print, and console.log for JS. \$\endgroup\$ – Redwolf Programs Jul 28 at 17:28
  • 4
    \$\begingroup\$ When we decide on an answer it goes here. codegolf.meta.stackexchange.com/questions/2447/… There's an INPUT case for SQL but no OUTPUT case. \$\endgroup\$ – Joshua Jul 28 at 18:38
  • \$\begingroup\$ Are you talking about MSSQL, T-SQL, MySQL/MariaBD, SQLite, PostgreSQL or some other? \$\endgroup\$ – Ismael Miguel Jul 29 at 11:45
  • \$\begingroup\$ I personally use mssql/tsql, but I guess such choice would be present in other dbmss too. \$\endgroup\$ – George Menoutis Jul 29 at 11:48
  • \$\begingroup\$ @GeorgeMenoutis MySQL doesn't support the print statement. The closest you have is SELECT 'Hello world!' as '' (just SELECT 'Hello world!' works but shows the text twice, once on the column name and once on the content). Or \! echo 'Hello world!'; but that's just calling the echo statement from the console (stackoverflow.com/a/61375812). \$\endgroup\$ – Ismael Miguel Jul 29 at 14:18
  • \$\begingroup\$ @IsmaelMiguel, but that way you will have a leading newline. Why not “--skip-column-names, -N Do not write column names in results.”? i.stack.imgur.com/xwPNY.png \$\endgroup\$ – manatwork Jul 30 at 11:33
  • \$\begingroup\$ @manatwork There are rules in place about flags. And I doubt that all SQL implementations (or most) have those flags. Or they do have it, but also have the print statement. Also, I doubt that people will be running the scripts directly from the console. They will probably have an online environment to try it, or a website with an SQL IDE, where that option doesn't exist. But, if an answer for MySQL specifies it, why not? Maybe should be part of the rules? \$\endgroup\$ – Ismael Miguel Jul 30 at 11:39
  • \$\begingroup\$ Also works when running SQL script file. PostgreSQL has “-t, --tuples-only Turn off printing of column names and result row count footers, etc.”, but have to also use “-A, --no-align Switches to unaligned output mode.” There your empty alias trick doesn't work. In SQLite there is “-[no]header Turn headers on or off.” but the no is the default anyway. i.stack.imgur.com/1Hmjn.png \$\endgroup\$ – manatwork Jul 30 at 12:10

You must log in to answer this question.

Browse other questions tagged .