code: static Object getPostgreSqlValue(Entity entity, Attribute attr) {
      String attrName = attr.getName();
      AttributeType attrType = attr.getDataType();
  
      switch (attrType) {
        case BOOL:
          return entity.getBoolean(attrName);
        case CATEGORICAL:
        case XREF:
          Entity xrefEntity = entity.getEntity(attrName);
          return xrefEntity != null
              ? getPostgreSqlValue(xrefEntity, xrefEntity.getEntityType().getIdAttribute())
              : null;
        case CATEGORICAL_MREF:
        case MREF:
        case ONE_TO_MANY:
          Iterable<Entity> entities = entity.getEntities(attrName);
          return stream(entities)
              .map(
                  mrefEntity ->
                      getPostgreSqlValue(mrefEntity, mrefEntity.getEntityType().getIdAttribute()))
              .collect(toList());
        case DATE:
          return entity.getLocalDate(attrName);
        case DATE_TIME:
          // As a workaround for #5674, we don't store milliseconds
          Instant instant = entity.getInstant(attrName);
          return instant != null ? instant.truncatedTo(ChronoUnit.SECONDS).atOffset(UTC) : null;
        case DECIMAL:
          return entity.getDouble(attrName);
        case EMAIL:
        case ENUM:
        case HTML:
        case HYPERLINK:
        case SCRIPT:
        case STRING:
        case TEXT:
          return entity.getString(attrName);
        case FILE:
          FileMeta fileEntity = entity.getEntity(attrName, FileMeta.class);
          return fileEntity != null
              ? getPostgreSqlValue(fileEntity, fileEntity.getEntityType().getIdAttribute())
              : null;
        case INT:
          return entity.getInt(attrName);
        case LONG:
          return entity.getLong(attrName);
        case COMPOUND:
          throw new IllegalAttributeTypeException(attrType);
        default:
          throw new UnexpectedEnumException(attrType);
      }
    }
docs: Returns the PostgreSQL value for the given entity attribute
  
  @param entity entity
  @param attr attribute
  @return PostgreSQL value