Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: RFC: Name and/or API for module ("Type::FromData") ( infer sql best guess cast type match sqltranslator )

by tobyink (Abbot)
on Apr 10, 2014 at 11:32 UTC ( #1081798=note: print w/ replies, xml ) Need Help??


in reply to Re: RFC: Name and/or API for module ("Type::FromData") ( infer sql best guess cast type match sqltranslator )
in thread RFC: Name and/or API for module ("Type::FromData")

You can create a sub in Perl called foo*bar. (Yes, including the asterisk.) You can't do it the normal way like this, because that's bad syntax:

sub foo*bar { return 42; } print foo*bar(), "\n";

But all is fine and dandy if you quote the name properly (i.e. use symbolic references):

my $name = "foo*bar"; *$name = sub { return 42; }; print &$name(), "\n";

Similarly, PostgreSQL is perfectly happy for you to name a column "when". It's just that the syntax of SQL requires you to quote it.

$ psql tai psql (9.1.13) Type "help" for help. tai=# CREATE TABLE "foo" ("when" varchar, "select" varchar, "update" v +archar); CREATE TABLE tai=# INSERT INTO "foo" VALUES ('a','b','c'); INSERT 0 1 tai=# SELECT * FROM "foo"; when | select | update ------+--------+-------- a | b | c (1 row) tai=# DROP TABLE "foo"; DROP TABLE tai=#

(For MySQL, the quote character is ` instead of ", though MySQL does have an option to let it speak proper, grown-up SQL.)

If you're writing code that needs to deal with an unknown database schema, you should always quote SQL identifier names (e.g. table names, column names) because you don't know what kind of crazy stuff is going to get thrown at you.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name


Comment on Re^2: RFC: Name and/or API for module ("Type::FromData") ( infer sql best guess cast type match sqltranslator )
Select or Download Code
Re^3: RFC: Name and/or API for module ("Type::FromData") ( infer sql best guess cast type match sqltranslator )
by chacham (Curate) on Apr 10, 2014 at 18:52 UTC
    Quoting retains case, meaning it will have to be quoted when used, which can be quite inconvenient and very confusing.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1081798]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-11-01 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (228 votes), past polls