0

I'm using Liquibase to build a Postgres SQL table. I have a column I'd like to add a check constraint to in order to ensure that the values in this column are in my set of acceptable values. I've found some documentation on how to do an addCheckConstraint but this seems to be for adding a check constraint to an already existing column. I don't need to do that, I have not yet created this table and would like to just include in the same changeset that is creating the table.

In my XML this is what I've got, autocomplete got me here so I know the tag should be valid, but I'm unsure what to actually put in it.

<column name="size" type="varchar">
    <constraints checkConstraint="what goes here?"
</column>

The "size" column can only contain the values "small", "medium", or "large". How can I accomplish this?

intA
  • 2,513
  • 12
  • 41
  • 66
  • You need to put that into a `` tag. –  Oct 03 '22 at 20:45
  • looks like it's your case: https://stackoverflow.com/a/5133540 – Rostyslav Barmakov Oct 03 '22 at 21:11
  • @a_horse_with_no_name so this is not what the tag is for? I get that I can do it with a SQL statement, just preferred to use Liquibase's built-in tags for as much as possible if available. Felt like the tag with a `checkConstraint` value was exactly what I needed, just didn't know the syntax of what goes in the `checkConstraint` field – intA Oct 04 '22 at 14:59
  • @RostyslavBarmakov same deal here, this is using the tag, which I'm aware I can do, just preferred to do it with built-in liquibase tags if available. And it seemed the tag was exactly what I needed. But I guess not – intA Oct 04 '22 at 15:00
  • [As documented in the manual](https://docs.liquibase.com/change-types/add-check-constraint.html) `` is only available in the pro (=paid) version. If you have a valid license key, you _can_ use it. –  Oct 04 '22 at 16:18
  • @a_horse_with_no_name that is for adding a check constraint to an existing column, which is different from the column sub-tag of that goes in the definition of the column when you create it . It is listed under the sub-tags [here](https://docs.liquibase.com/concepts/changelogs/attributes/column.html). But maybe it is still a pro feature? – intA Oct 04 '22 at 17:31

0 Answers0