1

I was wondering if there are some example coding to create dynamic tables with x columns? I am worried about column names having funny characters.

regards, Gordon

2 Answers 2

2

I guess you want escape these characters in table names. Use quote_identifier DBI method

Sign up to request clarification or add additional context in comments.

Comments

0

Why would you want to dynamically create tables? You ought to be designing a suitable database schema to suit the data you need to store.

My impression based on your question is that you're doing it wrong.

Creating tables is easily done with a standard CREATE TABLE command, though, for instance:

$dbh->do('CREATE TABLE testtable (foo VARCHAR(100), bar INT(4), baz DATETIME);');

You could generate that SQL easily enough, and there's no reason you should end up with any "funny characters".

I'm still not convinced that this is the right solution to whatever you're trying to do though, perhaps you could expand the question with more information on why you're trying to do this, as I get the feeling it's not thought through fully and will end up with a database structure that's an unmaintainable mess.

If you're trying to store dynamic data that doesn't fit well into a traditional relational database schema, you could also consider document-centric databases like MongoDB (which stores JSON-based "documents" of data, giving you a lot of flexibility; there's a MongoDB module on CPAN to interface with it easily).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.