diff --git a/src/bin/pg_dump/pg_backup_archiver.cpp b/src/bin/pg_dump/pg_backup_archiver.cpp index dfd4491c9..7600bac2d 100644 --- a/src/bin/pg_dump/pg_backup_archiver.cpp +++ b/src/bin/pg_dump/pg_backup_archiver.cpp @@ -203,6 +203,7 @@ static ParallelStateEntry* GetMyPSEntry(ParallelState* pstate); static void archive_close_connection(int code, void* arg); static void take_down_nsname_in_drop_stmt(const char *stmt, char *result, int len); static void get_role_password(RestoreOptions* opts); +static char* GetBehaviorCompatOptions(ArchiveHandle* fout); /* * Wrapper functions. @@ -2835,6 +2836,11 @@ static void _doSetFixedOutputState(ArchiveHandle* AH) if (findDBCompatibility(&AH->publicArc, PQdb(GetConnection(&AH->publicArc))) && hasSpecificExtension(&AH->publicArc, "dolphin")) (void)ahprintf(AH, "SET dolphin.sql_mode = 'sql_mode_full_group,pipes_as_concat,ansi_quotes,pad_char_to_full_length';\n"); + /* set behavior_compat_options */ + char* compatOptions = GetBehaviorCompatOptions(AH); + (void)ahprintf(AH, "SET behavior_compat_options = '%s';\n", compatOptions); + free(compatOptions); + (void)ahprintf(AH, "\n"); } @@ -5292,4 +5298,21 @@ bool hasSpecificExtension(Archive* fout, const char* extensionName) PQclear(res); destroyPQExpBuffer(query); return ntups != 0; +} + +static char* GetBehaviorCompatOptions(ArchiveHandle* fout) +{ + char* val = NULL; + PGresult* res = PQexec(fout->connection, "show behavior_compat_options;"); + + if (res != NULL && PQresultStatus(res) == PGRES_TUPLES_OK) { + val = gs_strdup(PQgetvalue(res, 0, 0)); + } else { + val = gs_strdup(""); + } + + PQclear(res); + res = NULL; + + return val; } \ No newline at end of file diff --git a/src/test/regress/input/test_float_dump.source b/src/test/regress/input/test_float_dump.source new file mode 100644 index 000000000..48896516b --- /dev/null +++ b/src/test/regress/input/test_float_dump.source @@ -0,0 +1,30 @@ +create database test_float_dump; +\c test_float_dump +set search_path to test_float_dump; + +\c postgres +ALTER DATABASE test_float_dump SET behavior_compat_options TO 'float_as_numeric'; + +\c test_float_dump +show behavior_compat_options; +set behavior_compat_options = 'float_as_numeric'; + +create table test_float (c1 int, c2 float); +insert into test_float values (1, 3.14); +insert into test_float values (2, 1.79E+10); +insert into test_float values (3, -0.01); +select * from test_float order by c1; + +\! @abs_bindir@/gs_dump test_float_dump -p @portstring@ -f @abs_bindir@/test_float_dump.sql -F p -w >/dev/null 2>&1; echo $? + +drop table test_float; +\d + +\! @abs_bindir@/gsql -d test_float_dump -p @portstring@ -f @abs_bindir@/test_float_dump.sql; + +select * from test_float order by c1; + +drop table test_float; + +\c postgres +drop database test_float_dump; \ No newline at end of file diff --git a/src/test/regress/output/cursor_expression_dump.source b/src/test/regress/output/cursor_expression_dump.source index 315791618..75c493225 100644 --- a/src/test/regress/output/cursor_expression_dump.source +++ b/src/test/regress/output/cursor_expression_dump.source @@ -80,6 +80,7 @@ SET SET SET SET +SET CREATE SCHEMA ALTER SCHEMA SET diff --git a/src/test/regress/output/event_trigger_dump_restore.source b/src/test/regress/output/event_trigger_dump_restore.source index 572c821e3..6b0ae8e1d 100644 --- a/src/test/regress/output/event_trigger_dump_restore.source +++ b/src/test/regress/output/event_trigger_dump_restore.source @@ -44,6 +44,7 @@ SET SET SET SET +SET CREATE FUNCTION ALTER FUNCTION CREATE EVENT TRIGGER diff --git a/src/test/regress/output/mysql_function.source b/src/test/regress/output/mysql_function.source index 3bfe26648..260aec06d 100755 --- a/src/test/regress/output/mysql_function.source +++ b/src/test/regress/output/mysql_function.source @@ -115,6 +115,7 @@ select usename from pg_user where usesysid = (select proowner from pg_proc wher --? .* --? .* --? .* +--? .* \c mysqltestbak \sf proc_definer1 CREATE DEFINER = testusr1 PROCEDURE public.proc_definer1() diff --git a/src/test/regress/output/plpgsql_dump.source b/src/test/regress/output/plpgsql_dump.source index 6fb294368..4c3f5633f 100644 --- a/src/test/regress/output/plpgsql_dump.source +++ b/src/test/regress/output/plpgsql_dump.source @@ -112,6 +112,7 @@ SET SET SET SET +SET CREATE SCHEMA ALTER SCHEMA SET diff --git a/src/test/regress/output/test_float_dump.source b/src/test/regress/output/test_float_dump.source new file mode 100644 index 000000000..bf4c26cd2 --- /dev/null +++ b/src/test/regress/output/test_float_dump.source @@ -0,0 +1,64 @@ +create database test_float_dump; +\c test_float_dump +set search_path to test_float_dump; +\c postgres +ALTER DATABASE test_float_dump SET behavior_compat_options TO 'float_as_numeric'; +\c test_float_dump +show behavior_compat_options; + behavior_compat_options +------------------------- + float_as_numeric +(1 row) + +set behavior_compat_options = 'float_as_numeric'; +create table test_float (c1 int, c2 float); +insert into test_float values (1, 3.14); +insert into test_float values (2, 1.79E+10); +insert into test_float values (3, -0.01); +select * from test_float order by c1; + c1 | c2 +----+------------- + 1 | 3.14 + 2 | 17900000000 + 3 | -.01 +(3 rows) + +\! @abs_bindir@/gs_dump test_float_dump -p @portstring@ -f @abs_bindir@/test_float_dump.sql -F p -w >/dev/null 2>&1; echo $? +0 +drop table test_float; +\d + List of relations + Schema | Name | Type | Owner | Storage +--------+------+------+-------+--------- +(0 rows) + +\! @abs_bindir@/gsql -d test_float_dump -p @portstring@ -f @abs_bindir@/test_float_dump.sql; +SET +SET +SET +SET +SET +SET +SET +SET +SET +SET +SET +CREATE TABLE +ALTER TABLE +REVOKE +REVOKE +GRANT +GRANT +--?.* +select * from test_float order by c1; + c1 | c2 +----+------------- + 1 | 3.14 + 2 | 17900000000 + 3 | -.01 +(3 rows) + +drop table test_float; +\c postgres +drop database test_float_dump; diff --git a/src/test/regress/output/view_definer_test.source b/src/test/regress/output/view_definer_test.source index 767628135..4843666ef 100755 --- a/src/test/regress/output/view_definer_test.source +++ b/src/test/regress/output/view_definer_test.source @@ -157,6 +157,7 @@ SET SET SET SET +SET CREATE TABLE ALTER TABLE CREATE VIEW diff --git a/src/test/regress/parallel_schedule0A b/src/test/regress/parallel_schedule0A index 1f9aadadf..819c7cb6e 100644 --- a/src/test/regress/parallel_schedule0A +++ b/src/test/regress/parallel_schedule0A @@ -472,7 +472,7 @@ test: select_into subselect_part2 gs_aggregate test: holdable_cursor cursor_expression cursor_expression_dump #test: portals_p2 window tsearch temp__6 col_subplan_base_2 -test: test_float test_numeric_with_neg_scale +test: test_float test_numeric_with_neg_scale test_float_dump test: alter_table_000 alter_table_002 alter_table_003 alter_table_modify #test: alter_table_001 alter_table_modify_ustore