You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These files are executed in the public schema because the connection retrieves its configuration from the dbConnectionParam variable which doesn't consider the schema specified by the user.
"Could not load pre/post/fk sql. Are you running from the correct path?",
file=sys.stderr,
)
sys.exit(-1)
try:
withpg.connect(dbConnectionParam) asconn:
withconn.cursor() ascur:
try:
withopen(dbFile, "rb") asxml:
# Pre-processing (dropping/creation of tables)
six.print_("Pre-processing ...")
ifpre!="":
cur.execute(pre)
The problem
This implies that if the user runs the command in a given schema twice, an error will occur because the following occurs
The user executes the script and specifies a given schema.
The DROP TABLE is executed in the public schema.
The CREATE TABLE is executed in the public schema.
The table is moved to the given schema.
Again, The user executes the script and specifies a given schema
The DROP TABLE is executed in the public schema even though the table exists in the specified schema because it was moved in the previous execution of the command.
The CREATE TABLE is executed in the public schema.
The table is moved from the public schema to the given schema which fails because the DROP TABLE didn't drop the table in the given schema but in the public schema.
Example
The following code blocks shows an example of this happening
This will drop the Users table. Are you sure [y/n]?y
Pre-processing ...
Pre-processing took 0.0 seconds
Processing data ...
Table 'Users' processing took 0.0 seconds
Post processing ...
Post processing took 0.0 seconds
This will drop the Users table. Are you sure [y/n]?y
Pre-processing ...
Pre-processing took 0.0 seconds
Processing data ...
Table 'Users' processing took 0.0 seconds
Post processing ...
Post processing took 0.0 seconds
Error in dealing with the database.
pg.Error (42P07): ERROR: relation "users" already exists in schema "foo"
relation "users" already exists in schema "foo"
The text was updated successfully, but these errors were encountered:
rodrigomorales1
changed the title
DROP TABLE statements are executed in the public schema which implies that tables are not dropped in the given schemaDROP TABLE statements are only executed in the public schema
Aug 18, 2021
Prologue
I've noticed that
*_pre.sql
files have two statements:DROP TABLE
andCREATE TABLE
. See some examples below.stackexchange-dump-to-postgres/sql/Users_pre.sql
Lines 1 to 2 in 49d8358
stackexchange-dump-to-postgres/sql/Badges_pre.sql
Lines 1 to 2 in 49d8358
stackexchange-dump-to-postgres/sql/Tags_pre.sql
Lines 1 to 2 in 49d8358
These files are executed in the
public
schema because the connection retrieves its configuration from thedbConnectionParam
variable which doesn't consider the schema specified by the user.stackexchange-dump-to-postgres/load_into_pg.py
Lines 185 to 203 in 49d8358
The problem
This implies that if the user runs the command in a given schema twice, an error will occur because the following occurs
DROP TABLE
is executed in thepublic
schema.CREATE TABLE
is executed in thepublic
schema.DROP TABLE
is executed in thepublic
schema even though the table exists in the specified schema because it was moved in the previous execution of the command.CREATE TABLE
is executed in thepublic
schema.public
schema to the given schema which fails because theDROP TABLE
didn't drop the table in the given schema but in thepublic
schema.Example
The following code blocks shows an example of this happening
The text was updated successfully, but these errors were encountered: