citusdata / pg_shard

ATTENTION: pg_shard is superseded by Citus, its more powerful replacement
https://github.com/citusdata/citus
GNU Lesser General Public License v3.0
1.06k stars 63 forks source link

Bugfix deparse constraint#94 #104

Closed onderkalaci closed 9 years ago

onderkalaci commented 9 years ago

Fixes #94

onderkalaci commented 9 years ago

@jasonmp85 After our chat, I understand the bug. Yes, as you suggest, we already find all check constraints(column and table) in the table and convert them to table constraints. The following quote from the PostgreSQL documentation also reinforces our approach:

We say that the first two constraints are column constraints, whereas the third one is a table constraint because it is written separately from any one column definition. Column constraints can also be written as table constraints, while the reverse is not necessarily possible, since a column constraint is supposed to refer to only the column it is attached to. (PostgreSQL doesn't enforce that rule, but you should follow it if you want your table definitions to work with other database systems.)

This commit fixes DeparseCreateStmt function, in which we fail to add a comma for the first table constraint that is deparsed. Since we forget the first comma after column definitions, the first table constraint was considered as column constraint.

Basically, I tried to use the same approach in pg_shard_get_tableschemadef_string, which works as expected.

jasonmp85 commented 9 years ago

Looks good. Merging this!

:shipit: