Use (BIG)SERIAL in generated SQL when this was used when column
originally defined. This is recognized by the fact that the column has a dependency on a sequence. For columns that happen to have a default which uses a pre exising sequence the dependency is the other way around.
This commit is contained in:
parent
817a371220
commit
2c2253f75e
3 changed files with 26 additions and 9 deletions
|
|
@ -6,15 +6,26 @@
|
|||
#include "PgTypeContainer.h"
|
||||
#include "PgCollation.h"
|
||||
#include "PgCollationContainer.h"
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
QString PgAttribute::columnDefinition(const PgDatabaseCatalog &cat) const
|
||||
{
|
||||
// create: column_name data_type [ COLLATE collation ] [ column_constraint [ ... ]
|
||||
// alter: column_name data_type [ COLLATE collation ] [ column_constraint [ ... ]
|
||||
// constraints NULL/NOT NULL, DEFAULT, GENERATED other constraints will be ignored here a
|
||||
auto&& type = cat.types()->getByKey(typid);
|
||||
QString type_str;
|
||||
if (isSerial()) {
|
||||
if (typid == Pgsql::int4_oid)
|
||||
type_str = "SERIAL";
|
||||
else if (typid == Pgsql::int8_oid)
|
||||
type_str = "BIGSERIAL";
|
||||
}
|
||||
else {
|
||||
auto&& type = cat.types()->getByKey(typid);
|
||||
type_str = type->objectName();
|
||||
}
|
||||
|
||||
QString sql = quoteIdent(name) % " " % type->objectName();
|
||||
QString sql = quoteIdent(name) % " " % type_str;
|
||||
if (collation != InvalidOid) {
|
||||
auto&& col = cat.collations()->getByKey(collation);
|
||||
QString oname = col->objectName();
|
||||
|
|
@ -25,7 +36,7 @@ QString PgAttribute::columnDefinition(const PgDatabaseCatalog &cat) const
|
|||
if (notnull)
|
||||
sql += " NOT NULL";
|
||||
|
||||
if (hasdef)
|
||||
if (hasdef && !isSerial())
|
||||
sql += " DEFAULT " % defaultValue;
|
||||
|
||||
if (identity != '\0') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue