-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Alter .. RENAME SQL #146
Conversation
CREATE DOMAIN us_postal_code AS TEXT CHECK( VALUE ~ '^\d{5}$' OR VALUE ~ '^\d{5}-\d{4}$' );
`deparse_renamestmt': Can't deparse: {"renameType"=>47, "relationType"=>0, "relation"=>{"RangeVar"=>{"relname"=>"foo", "inh"=>true, "relpersistence"=>"p", "location"=>11}}, "newname"=>"bar", "behavior"=>0} (RuntimeError) ALTER VIEW "foo" RENAME TO "bar"
`deparse_renamestmt': Can't deparse: {"renameType"=>47, "relationType"=>0, "relation"=>{"RangeVar"=>{"relname"=>"foo", "inh"=>true, "relpersistence"=>"p", "location"=>11}}, "newname"=>"bar", "behavior"=>0} (RuntimeError) ALTER VIEW "foo" RENAME TO "bar"
lib/pg_query/deparse.rb
Outdated
output << deparse_item(node['relation']) | ||
output << 'RENAME TO' | ||
output << node['newname'] | ||
output << deparse_identifier(node['newname'], escape_always: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify why we need to escape this one always?
I mostly added that as a legacy option to avoid breaking too many tests, but I think going forward this should not be used if we can avoid it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ALTER VIEW "foo" RENAME TO "Bar"
if execute this sql without (escape_always: true) options, deparser result is ALTER VIEW "foo" RENAME TO Bar
. If you execute deparser sql, rename the view as a bar not Bar.
So we need this options.
ALTER TRIGGER "emp_stamp" ON "emp" RENAME TO "emp_track_chgs" ALTER FUNCTION "sqrt"(int) RENAME TO "square_root" ALTER MATERIALIZED VIEW "foo" RENAME TO "bar" ALTER CONVERSION "iso_8859_1_to_utf8" RENAME TO "latin1_to_unicode" ALTER DOMAIN "zipcode" RENAME CONSTRAINT zipchk TO "zip_check" ALTER COLLATION "de_DE" RENAME TO "german" ALTER AGGREGATE "myavg"(int) RENAME TO "my_average" ALTER TABLE "distributors" RENAME COLUMN address TO "city" ALTER TABLE "distributors" RENAME CONSTRAINT zipchk TO "zip_check" ALTER TYPE "electronic_mail" RENAME TO "email" ALTER INDEX "distributors" RENAME TO "suppliers" ALTER TABLESPACE index_space RENAME TO "fast_raid" ALTER TRIGGER "emp_stamp" ON "emp" RENAME TO "emp_track_chgs" ALTER RULE notify_all ON "emp" RENAME TO "notify_me"
ALTER TRIGGER "emp_stamp" ON "emp" RENAME TO "emp_track_chgs"
ALTER FUNCTION "sqrt"(int) RENAME TO "square_root"
ALTER MATERIALIZED VIEW "foo" RENAME TO "bar"
ALTER CONVERSION "iso_8859_1_to_utf8" RENAME TO "latin1_to_unicode"
ALTER DOMAIN "zipcode" RENAME CONSTRAINT zipchk TO "zip_check"
ALTER COLLATION "de_DE" RENAME TO "german"
ALTER AGGREGATE "myavg"(int) RENAME TO "my_average"
ALTER TABLE "distributors" RENAME COLUMN address TO "city"
ALTER TABLE "distributors" RENAME CONSTRAINT zipchk TO "zip_check"
ALTER TYPE "electronic_mail" RENAME TO "email"
ALTER INDEX "distributors" RENAME TO "suppliers"
ALTER TABLESPACE index_space RENAME TO "fast_raid"
ALTER TRIGGER "emp_stamp" ON "emp" RENAME TO "emp_track_chgs"
ALTER RULE notify_all ON "emp" RENAME TO "notify_me"