Getting the schema for a DB table
Ash Berlin
ash_cpan at firemirror.com
Sun May 25 20:11:20 BST 2014
`sqlt` from SQL::Translator can also give this ISTR http://search.cpan.org/~frew/SQL-Translator-0.11018/script/sqlt:
sqlt -d -f DBI-PostgreSQL -t PostgreSQL --dsn dbi:Pg:dbname=CMS
Might be a bit flakey with some more advanced Pg features - my version is quite out of date though.
Thomas' solution might be more reliable for what you actually want to achieve.
-ash
On 25 May 2014, at 17:46, Simon Wistow <simon at thegestalt.org> wrote:
> [ Continuing the series of "Simon doesn't really do Perl (or
> programming) that much anymore and therefore asks dumb questions" ]
>
> I'm looking for something that can be pointed at a DB table and can give
> the schema for the table back - preferably in the form of an SQL CREATE
> TABLE statement but I can live without[*].
>
> DBIx::DBSchema seems to be just the ticket
>
> my $schema = DBIx::DBSchema->new_native($dbh);
> my $sql = $schema->table($table)->sql_create_table($dbh);
>
> Except I've been running into a bunch of bugs.
>
> Any other solutions?
>
> Alternatively - what I'm really trying to do is get a unique finger
> print for the schema of a database. My current plan is hashing the
> CREATE TABLE statement but other methods would be gratefully received.
>
> Simon
>
> [*] Of course in MySQL I can do SHOW CREATE TABLE ... but that's not
> portable.
More information about the london.pm
mailing list