Skip to content

Conversation

@ryanvarley
Copy link
Contributor

@ryanvarley ryanvarley commented Oct 9, 2025

If you subtract two numeric columns from each other piccolo will subtract it from itself.

e.g.

class MyTable(Table):
    integer = Integer(null=True)
    other_integer = Integer(null=True)

print(MyTable.integer - MyTable.other_integer) produces other_integer - other_integer

Issue #1261

@ryanvarley ryanvarley marked this pull request as draft October 9, 2025 11:11
@ryanvarley ryanvarley closed this Oct 9, 2025
@ryanvarley ryanvarley reopened this Oct 9, 2025

class MyTable(Table):
integer = Integer(null=True)
other_integer = Integer(null=True, default=5)
Copy link
Contributor Author

@ryanvarley ryanvarley Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no way i can see of setting initial values on two columns in this test suite so defining here as a demonstration

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine.

querystring=MyTable.integer + MyTable.other_integer,
expected=1005,
),
OperatorTestCase(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These wont pass due to >< not being valid operators currently

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we might have to leave the > and < for another PR.

def get_querystring(
self,
column_name: str,
operator: Literal["+", "-", "/", "*"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<> not valid?

Copy link
Member

@dantownsend dantownsend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great - thanks!

I'd remove the test cases for > and < for now (we can tackle that in a separate PR) and then I think this is good to go.

Looks like one of our integration tests is failing, but we'll fix that in a separate PR then update this one.

querystring=MyTable.integer + MyTable.other_integer,
expected=1005,
),
OperatorTestCase(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we might have to leave the > and < for another PR.


class MyTable(Table):
integer = Integer(null=True)
other_integer = Integer(null=True, default=5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine.

@dantownsend
Copy link
Member

If you update this branch from main, the integration tests should now pass 👍

@dantownsend dantownsend merged commit dd3002e into piccolo-orm:master Oct 11, 2025
46 checks passed
@dantownsend
Copy link
Member

@ryanvarley I went ahead and merged it in, so it can be in the next release. Thanks a lot for this fix 👍

@ryanvarley
Copy link
Contributor Author

Awesome, thanks for the quick review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants