function get_create_syntax( $table )
{
$qry = "
SELECT *
FROM $table
LIMIT 1
";
$res = pg_query( $qry );
$row = pg_fetch_assoc( $res );
$create = "CREATE TABLE $table \n(\n";
$item = array();
for( $i = 0; $i < count( $row ); $i++ )
{
$name = pg_field_name( $res, $i );
$type = pg_field_type( $res, $i );
$size = pg_field_size( $res, $i );
$item[$i] = '"'.$name.'" '.$type;
$qry = "
SELECT a.atttypmod AS size,
a.attnotnull AS notnull
FROM pg_attribute AS a,
pg_class AS c
WHERE c.relname = '$table'
AND a.attrelid = c.oid
AND a.attname = '$name'
";
$res2 = pg_query( $qry );
$out = pg_fetch_object( $res2 );
if( $out -> size != -1 )
{
$item[$i] .= '('.( $out -> size - 4 ).')';
}
if( $out -> notnull == 't' )
$item[$i] .= ' NOT';
$item[$i] .= ' NULL';
}
$create .= implode( ",\n", $item ) ."\n);";
return $create;
}