Search code examples
sqlpostgresqluuid

No filter for uuid in postgresql


I want to do a filter in SQL where no value of an uuid is matched. That is, a where condition where no row is matched by the condition.

With a regular int4 id, I would do:

where my_id = -1

If I do the same thing with the uuid, I get:

where my_uuid = '-1'

I get an error:

ERROR: invalid input syntax for type uuid: "-1"

How can I do this with an uuid? I would need to use a =, so solutions of the form

where my_uuid is null

don't work for me. Thanks in advance!


Solution

  • What about

    '00000000-0000-0000-0000-000000000000'::uuid
    

    That is just as good an "impossible value" as -1 is for an integer (both are not really impossible).