Skip to content

Commit b60012d

Browse files
committed
add generate and identity columns
add generate and identity columns add storage opts for PG12
1 parent 9b97fa1 commit b60012d

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ This text Russian language.
112112
* исправлено падение в режиме редактирования
113113
* исправлено редактирование процедур без аргументов
114114

115+
15.04.2020
116+
* в окне SQL инструкции создания таблицы теперь отображаются новые параметры хранения
117+
* в описании колонок учтены generated и identity колонки
118+
115119

116120

117121

Release_(3.0)/pgAdmin3.exe

4.5 KB
Binary file not shown.

include/schema/pgColumn.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,22 @@ class pgColumn : public pgTableObject
237237
{
238238
serialSchema = s;
239239
}
240+
wxString GetGenerated() const
241+
{
242+
return generated;
243+
}
244+
void iSetGenerated(const wxString &s)
245+
{
246+
generated = s;
247+
}
248+
wxString GetIdentity() const
249+
{
250+
return identity;
251+
}
252+
void iSetIdentity(const wxString &s)
253+
{
254+
identity = s;
255+
}
240256
void iSetPkCols(const wxString &s)
241257
{
242258
pkCols = s;
@@ -299,7 +315,7 @@ class pgColumn : public pgTableObject
299315

300316
private:
301317
wxString varTypename, quotedTypename, defaultVal, tableName, quotedFullTable, defaultStorage, storage, rawTypename;
302-
wxString serialSequence, serialSchema, pkCols, inheritedTableName, collation;
318+
wxString serialSequence, serialSchema, pkCols, inheritedTableName, collation, generated, identity;
303319
long colNumber, length, precision, statistics, attstattarget;
304320
long typlen, typmod, inheritedCount;
305321
bool isPK, isFK, notNull, isArray, isLocal;

schema/pgColumn.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,14 @@ wxString pgColumn::GetDefinition()
410410
{
411411
if (GetNotNull())
412412
sql += wxT(" NOT NULL");
413-
AppendIfFilled(sql, wxT(" DEFAULT "), GetDefault());
413+
if (!GetGenerated().IsEmpty()) {
414+
if (GetGenerated()=="s") sql+= " GENERATED ALWAYS AS " + GetDefault() + " STORED";
415+
} else if (!GetIdentity().IsEmpty()) {
416+
if (GetIdentity()=="a") sql+= " GENERATED ALWAYS AS IDENTITY";
417+
if (GetIdentity()=="d") sql+= " GENERATED BY DEFAULT AS IDENTITY" ;
418+
}
419+
else
420+
AppendIfFilled(sql, wxT(" DEFAULT "), GetDefault());
414421
}
415422
return sql;
416423
}
@@ -618,7 +625,7 @@ pgObject *pgColumnFactory::CreateObjects(pgCollection *coll, ctlTree *browser, c
618625
sql += wxT(",\n(SELECT array_agg(label) FROM pg_seclabels sl1 WHERE sl1.objoid=att.attrelid AND sl1.objsubid=att.attnum) AS labels");
619626
sql += wxT(",\n(SELECT array_agg(provider) FROM pg_seclabels sl2 WHERE sl2.objoid=att.attrelid AND sl2.objsubid=att.attnum) AS providers");
620627
}
621-
628+
622629
sql += wxT("\n")
623630
wxT(" FROM pg_attribute att\n")
624631
wxT(" JOIN pg_type ty ON ty.oid=atttypid\n")
@@ -653,6 +660,17 @@ pgObject *pgColumnFactory::CreateObjects(pgCollection *coll, ctlTree *browser, c
653660
column->iSetComment(columns->GetVal(wxT("description")));
654661
column->iSetSerialSequence(columns->GetVal(wxT("sername")));
655662
column->iSetSerialSchema(columns->GetVal(wxT("serschema")));
663+
if (database->BackendMinimumVersion(10, 0))
664+
{
665+
column->iSetIdentity(columns->GetVal(wxT("attidentity")));
666+
};
667+
if (database->BackendMinimumVersion(12, 0))
668+
{
669+
column->iSetGenerated(columns->GetVal(wxT("attgenerated")));
670+
};
671+
672+
673+
656674
column->iSetPkCols(columns->GetVal(wxT("indkey")));
657675
if (database->BackendMinimumVersion(7, 4))
658676
column->iSetIsFK(columns->GetBool(wxT("isfk")));

schema/pgTable.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "schema/pgConstraints.h"
2929
#include "schema/gpPartition.h"
3030
#include "schema/pgPartition.h"
31-
31+
#include <wx/regex.h>
3232

3333
// App headers
3434

@@ -618,6 +618,25 @@ wxString pgTable::GetSql(ctlTree *browser)
618618
}
619619
}
620620
}
621+
wxRegEx reg("vacuum_index_cleanup=[a-z]+|vacuum_truncate=[a-z]+|parallel_workers=[0-9]+|toast_tuple_target=[0-9]+|log_autovacuum_min_duration=[0-9]+|user_catalog_table=[a-z]+");
622+
wxString relopt=GetRelOptions();
623+
wxString o;
624+
size_t start, len;
625+
while ( reg.Matches(relopt) )
626+
{
627+
reg.GetMatch(&start, &len, 0);
628+
o=reg.GetMatch(relopt, 0);
629+
AppendIfFilled(sqlopt, ",\n ", o);
630+
relopt = relopt.Mid (start + len);
631+
}
632+
relopt=GetToastRelOptions();
633+
while ( reg.Matches(relopt) )
634+
{
635+
reg.GetMatch(&start, &len, 0);
636+
o="toast." + reg.GetMatch(relopt, 0);
637+
AppendIfFilled(sqlopt, ",\n ", o);
638+
relopt = relopt.Mid (start + len);
639+
}
621640
if (!sqlopt.IsEmpty()) {
622641
sql += wxT("\nWITH (");
623642
if (sqlopt.Index(',')==0) sqlopt=sqlopt.Mid(1);

0 commit comments

Comments
 (0)