Conversation
This allows for the automatic overloading of the function, implementing therefore the col_is_pk( name, name, name[] ) as requested in issue theory#133. See issue theory#133.
format() has been introduced with 9.1 or so, and using it to easiliy compose messages produces errors in compatibility with older versions.
Due to the addition of variants methods the output of the test has changed.
theory
left a comment
There was a problem hiding this comment.
Yeah, if it is likely to break existing tests that don't have a cast, I'm not sure adding a new test function makes sense. I like supporting as many variants as possible, and am sad that I missed some when I originally wrote this thing.
OTOH, if it's the new variant that would require casting, and the old variant continued to work, that would be just fine. We have to decide what to do about DEFAULT and older versions of Postgres, though.
| -- col_is_pk( schema, table, column, description ) | ||
| CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT ) | ||
| -- col_is_pk( schema, table, column ) | ||
| CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT DEFAULT NULL ) |
There was a problem hiding this comment.
Omit DEFAULT until support for 8.3 is dropped.
| CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT DEFAULT NULL ) | ||
| RETURNS TEXT AS $$ | ||
| SELECT is( _ckeys( $1, $2, 'p' ), $3, $4 ); | ||
| SELECT is( _ckeys( $1, $2, 'p' ), $3, |
There was a problem hiding this comment.
Without support for DEFAULT, the pattern up to now has been to create separate functions for each signature. Unless @decibel or someone finishes the update to remove support for 9.0 and earlier, I think we need to stick to that pattern.
There was a problem hiding this comment.
Got it, I'll try to refactor as soon as I've time.
There was a problem hiding this comment.
master is no longer testing < 9.1, so I think DEFAULT is ok now. It'd be good to merge master though since it now has much more extensive automated testing.
2b4e6b8 to
0322ca7
Compare
test/sql/pktap.sql
Outdated
| ); | ||
|
|
||
| SELECT * FROM check_test( | ||
| col_is_pk( 'sometab', 'id'::name, 'sometab.id should be a pk' ), |
There was a problem hiding this comment.
Why is the name cast needed here? AFAICT requiring users to add that would break backwards compatibility, which I don't think we can do :(
There was a problem hiding this comment.
Unfortunately, https://travis-ci.org/theory/pgtap/jobs/614184912 shows that we have a problem when removing this cast. :(
One possible way to handle this would be C code, since we could then use one of the polymorphic pseudotypes. I'm not sure this feature is worth that though.
We could possibly have a config option to make to provide the old behavior.
Another possibility would be a version of the function that checked the first argument to see if it was a schema vs a table and acted accordingly (as well as throwing the correct error if neither existed). Before trying to code that we'd want to make sure we have full test cases for all the possible "does not exist" cases, both with and without a description provided. This would be unfortunately complex, but I think it's doable.
Well, or we could just tell people we're breaking backwards compatibility... but if we wanted to do that I think we'd need to do a 2.0.
There was a problem hiding this comment.
This is still an issue as well.
In current versions users do not need to cast, so we need to test without a cast.
Take back the work on this Pull Request, see comment <theory#178 (comment)>
|
I've done some moneky typing merging the master branch, and |
|
Looks like the ALTER EXTENSION UPDATE tests are failing (https://travis-ci.org/theory/pgtap/builds/615528764); is your latest code in |
|
Seems to me my branch is updated as commit 950c170 which does me the pktap test passing: I always get confused about travis, so I'm probably doing something wrong in my development platform, but I cannot see what. |
|
Ahh, I understand your confusion then. You're showing the results of running a single test (essentially, what
That means that the failure happened while running All that said, there's a bigger issue: your change will force users to add a cast in |
|
I'm having quite an hard time in finding resources to work on this. |
|
I pushed 8f4a881, an updated variant of #199, and then noticed this PR implementing the same feature, so I added thanks in ff4a30b. Super appreciate your work on this, @fluca1978! |
This is a potential implementation of #133, in particular
col_is_pk(name, name, name).I'm not sure this is something really required, because there is a potential clash with a textual overloaded function:
col_is_pk( name, name, name)requires explicit cast to not clahs withcol_is_pk( name, name, description).I'm not able to decide which is best approach, but sounds to me that
col_is_pk( 'public', 'foo', 'id' )is simpler thancol_is_pk( 'public', 'foo', 'id'::name ). Therefore I'm not sure this pull request is the right implementation, and before digging into 'isnt_col_pk' set of functions I would like comments.