-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Issue with columns named type
with PostgreSQL
#347
Comments
type
with PostgreSQL
It's just that the current parser of psqldef is still half-baked. It does have a better situation than other sqldef variants though. psqldef uses a hybrid parser system; it tries to parse SQL with PostgreSQL's original parser and convert it to sqldef AST, or just parse SQL with sqldef's original parser if the conversion is not supported in the first path. The plan is to handle everything in the first path, but it still fallbacks to the old parser in many cases, including this, and the old one doesn't handle this case well. If you remove some features that are not supported by the new conversion, The logic lives in |
I am interested however my go skills are very low. I traced the issue to: https://github.com/k0kubun/sqldef/blob/master/database/postgres/parser.go#L489 which only implements "NOT NULL" basically and the new parser fails on basically every other check: { "CONSTR_CHECK", 6 }, I imagine the other cases need to be added to the switch but I have no idea how to continue, if you could give me some pointers or some previous commits that would point me to the right direction, I would appreciate it. |
What I would do is:
Does that make sense? |
I did exactly that, using q.Q instead, same outcome, that's how I saw that the parser was not able to parse:
basically the new parser would fail with: unhandled contype: 7, then 3, then 6. I'm stuck on what to do next. Here is constraint object value for
and here is the same object with
I got to the part where I need something like:
My Go skill stops here, maybe I can revisit at a future time when I have more skill :) |
The next step is to add Next, you need to fill out those
This iteration should let the new parser be able to parse what the legacy parser can already parse. It would leave only a tiny little piece that the legacy parser can't parse. At that point, hopefully, you understand what the new parser needs to return. If not, please make that state a pull request, and I can give another comment from there. |
Probably, I faced the same issue as this one. CREATE TABLE tbl (value text);
ALTER TABLE tbl ADD CONSTRAINT tbl_value_idx UNIQUE (value);
It seems to cause an error when a column with the same name as the keywords defined in token.go is specified in alter table. I will try to parse alter table with the new parser. |
Platform
The issue that I'm seeing is that I need to wrap the keywork
type
in quotes to have a working run of psqldef. If I use :everything is working as expected, but I do not have control over the source schema unfortunately so I am curious why this happens and if there is a solution.
--export output
Input SQL
Current output
Expected output
The text was updated successfully, but these errors were encountered: